diff --git a/.gas-snapshot b/.gas-snapshot new file mode 100644 index 0000000..d7d549e --- /dev/null +++ b/.gas-snapshot @@ -0,0 +1,31 @@ +CirclesTest:testCalculateIssuance() (gas: 3729002) +CirclesTest:testConsecutiveClaimablePeriods() (gas: 375082) +CirclesTest:testDemurragedTransfer() (gas: 229055) +CompositeMintGroupsTest:testCompositeGroupMint() (gas: 212459) +DemurrageTest:testDemurrageFactor() (gas: 79139) +DemurrageTest:testFuzzStablePointIssuance(int192) (runs: 256, μ: 63114, ~: 63250) +DemurrageTest:testInversionGammaBeta64x64_100years() (gas: 958541) +DemurrageTest:testInversionGammaBeta64x64_100years_withExtension() (gas: 1083080) +DemurrageTest:testInversionGammaBeta64x64_100years_withExtension_comparison() (gas: 1703713) +DemurrageTest:testInversionGammaBeta64x64_20years() (gas: 221562) +DemurrageTest:testRepeatedDemurrage() (gas: 15264702) +ERC20LiftTest:testERC20Demurrage() (gas: 133270) +ERC20LiftTest:testERC20Wrap() (gas: 954629) +ERC20LiftTest:testWrapAndUnwrapInflationaryERC20() (gas: 89881) +GroupMintTest:testRegisterGroup() (gas: 165153) +HubPathTransferTest:testOperateFlowMatrixConsentedFlow() (gas: 265369) +MigrationTest:testConversionMigrationV1ToTimeCircles() (gas: 18365) +MintGroupCirclesTest:testDirectSelfGroupMintFails() (gas: 341135) +MintGroupCirclesTest:testGroupMint() (gas: 340165) +MintGroupCirclesTest:testGroupMintFail() (gas: 23302) +MintGroupCirclesTest:testGroupMintMany() (gas: 858065) +MintGroupCirclesTest:testGroupMintMultiCollateral() (gas: 755126) +MintGroupCirclesTest:testSequentialGroupMint() (gas: 511760) +NamesTest:testBase58Conversion() (gas: 78904) +NamesTest:testCustomName() (gas: 40809) +NamesTest:testInvalidCustomNames() (gas: 20017) +NamesTest:testMetadataDigest() (gas: 35073) +NamesTest:testShortName() (gas: 102230) +NamesTest:testShortNameWithNonce() (gas: 73360) +NamesTest:testShortNameWithPadding() (gas: 71662) +V1MintStatusUpdateTest:testMigrationFromV1DuringBootstrap() (gas: 2542748) \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0bbac1d..b4eb737 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,9 +2,9 @@ name: test on: push: - branches: [ master, develop ] + branches: [ master, develop, beta, candidate/stable ] pull_request: - branches: [ master, develop ] + branches: [ master, develop, beta, candidate/stable ] workflow_dispatch: env: @@ -42,3 +42,13 @@ jobs: run: | forge test -vvv id: test + + - name: Print compiled non-test contract sizes + run: | + forge build --skip test --sizes + id: build-sizes + + - name: Print gas difference against a pre-existing snapshot + run: | + forge snapshot --diff + id: gas-diff \ No newline at end of file diff --git a/.gitignore b/.gitignore index 52add64..38ce5f9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,8 +5,6 @@ out/ # docs -# gas snapshot files -.gas-snapshot # Ignores development broadcast logs !/broadcast diff --git a/src/circles/DiscountedBalances.sol b/src/circles/DiscountedBalances.sol index e698608..d7e985a 100644 --- a/src/circles/DiscountedBalances.sol +++ b/src/circles/DiscountedBalances.sol @@ -91,10 +91,7 @@ contract DiscountedBalances is Demurrage { // revert CirclesDemurrageAmountExceedsMaxUint192(_account, _id, _balance, 0); revert CirclesErrorAddressUintArgs(_account, _id, 0x81); } - DiscountedBalance memory discountedBalance = discountedBalances[_id][_account]; - discountedBalance.balance = uint192(_balance); - discountedBalance.lastUpdatedDay = _day; - discountedBalances[_id][_account] = discountedBalance; + discountedBalances[_id][_account] = DiscountedBalance({balance: uint192(_balance), lastUpdatedDay: _day}); } /** diff --git a/src/circles/ERC1155.sol b/src/circles/ERC1155.sol index b0a2dba..9d6d248 100644 --- a/src/circles/ERC1155.sol +++ b/src/circles/ERC1155.sol @@ -114,10 +114,7 @@ abstract contract ERC1155 is DiscountedBalances, Context, ERC165, IERC1155, IERC * @dev See {IERC1155-safeTransferFrom}. */ function safeTransferFrom(address _from, address _to, uint256 _id, uint256 _value, bytes memory _data) public { - address sender = _msgSender(); - if (_from != sender && !isApprovedForAll(_from, sender)) { - revert ERC1155MissingApprovalForAll(sender, _from); - } + _allowanceCheck(_from); _safeTransferFrom(_from, _to, _id, _value, _data); } @@ -131,10 +128,7 @@ abstract contract ERC1155 is DiscountedBalances, Context, ERC165, IERC1155, IERC uint256[] memory _values, bytes memory _data ) public virtual { - address sender = _msgSender(); - if (_from != sender && !isApprovedForAll(_from, sender)) { - revert ERC1155MissingApprovalForAll(sender, _from); - } + _allowanceCheck(_from); _safeBatchTransferFrom(_from, _to, _ids, _values, _data); } @@ -216,6 +210,16 @@ abstract contract ERC1155 is DiscountedBalances, Context, ERC165, IERC1155, IERC _acceptanceCheck(from, to, ids, values, data); } + /** + * @dev do the ERC1155 token the sender allowance check + */ + function _allowanceCheck(address _from) internal view { + address sender = _msgSender(); + if (_from != sender && !isApprovedForAll(_from, sender)) { + revert ERC1155MissingApprovalForAll(sender, _from); + } + } + /** * @dev do the ERC1155 token acceptance check to the receiver */ diff --git a/src/hub/Hub.sol b/src/hub/Hub.sol index 14e6a6d..33b4a75 100644 --- a/src/hub/Hub.sol +++ b/src/hub/Hub.sol @@ -273,7 +273,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors { // store the metadata digest for the avatar metadata if (_metadataDigest != bytes32(0)) { - nameRegistry.setMetadataDigest(msg.sender, _metadataDigest); + _setMetadataDigest(_metadataDigest); } } @@ -287,16 +287,7 @@ contract Hub is Circles, TypeDefinitions, IHubErrors { function registerGroup(address _mint, string calldata _name, string calldata _symbol, bytes32 _metadataDigest) external { - _registerGroup(msg.sender, _mint, standardTreasury, _name, _symbol); - - // for groups register possible custom name and symbol - nameRegistry.registerCustomName(msg.sender, _name); - nameRegistry.registerCustomSymbol(msg.sender, _symbol); - - // store the IPFS CIDv0 digest for the group metadata - nameRegistry.setMetadataDigest(msg.sender, _metadataDigest); - - emit RegisterGroup(msg.sender, _mint, standardTreasury, _name, _symbol); + registerCustomGroup(_mint, standardTreasury, _name, _symbol, _metadataDigest); } /** @@ -313,15 +304,15 @@ contract Hub is Circles, TypeDefinitions, IHubErrors { string calldata _name, string calldata _symbol, bytes32 _metadataDigest - ) external { + ) public { _registerGroup(msg.sender, _mint, _treasury, _name, _symbol); // for groups register possible custom name and symbol - nameRegistry.registerCustomName(msg.sender, _name); + _registerCustomName(_name); nameRegistry.registerCustomSymbol(msg.sender, _symbol); // store the metadata digest for the group metadata - nameRegistry.setMetadataDigest(msg.sender, _metadataDigest); + _setMetadataDigest(_metadataDigest); emit RegisterGroup(msg.sender, _mint, _treasury, _name, _symbol); } @@ -335,10 +326,10 @@ contract Hub is Circles, TypeDefinitions, IHubErrors { _insertAvatar(msg.sender); // for organizations, only register possible custom name - nameRegistry.registerCustomName(msg.sender, _name); + _registerCustomName(_name); // store the IPFS CIDv0 digest for the organization metadata - nameRegistry.setMetadataDigest(msg.sender, _metadataDigest); + _setMetadataDigest(_metadataDigest); emit RegisterOrganization(msg.sender, _name); } @@ -1228,4 +1219,20 @@ contract Hub is Circles, TypeDefinitions, IHubErrors { // update the expiry; checks must be done by caller trustMarker.expiry = _expiry; } + + /** + * @dev Calls nameRegistry to store the metadata digest. + * @param _metadataDigest sha256 metadata digest for the avatar metadata. + */ + function _setMetadataDigest(bytes32 _metadataDigest) private { + nameRegistry.setMetadataDigest(msg.sender, _metadataDigest); + } + + /** + * @dev Calls nameRegistry to register the custom name. + * @param _name immutable name of the group Circles or organization. + */ + function _registerCustomName(string calldata _name) private { + nameRegistry.registerCustomName(msg.sender, _name); + } } diff --git a/test/hub/MockDeployment.sol b/test/hub/MockDeployment.sol index bd4e183..273e5af 100644 --- a/test/hub/MockDeployment.sol +++ b/test/hub/MockDeployment.sol @@ -14,6 +14,7 @@ import "../lift/MockERC20Lift.sol"; import "./MockHub.sol"; contract MockDeployment { + bool public IS_TEST = true; // State variables MockHub public hub; diff --git a/test/hub/MockHub.sol b/test/hub/MockHub.sol index 02a9b83..6f53ece 100644 --- a/test/hub/MockHub.sol +++ b/test/hub/MockHub.sol @@ -4,6 +4,7 @@ pragma solidity >=0.8.24; import "../../src/hub/Hub.sol"; contract MockHub is Hub { + bool public IS_TEST = true; // Constructor constructor(uint256 _inflationDayZero, uint256 _bootstrapTime) diff --git a/test/hub/MockPathTransferHub.sol b/test/hub/MockPathTransferHub.sol index 643e331..d6c2faa 100644 --- a/test/hub/MockPathTransferHub.sol +++ b/test/hub/MockPathTransferHub.sol @@ -7,6 +7,7 @@ import "../../src/migration/IHub.sol"; import "../../src/names/INameRegistry.sol"; contract MockPathTransferHub is Hub { + bool public IS_TEST = true; // Constructor constructor(uint256 _inflationDayZero, uint256 _bootstrapTime)