Skip to content

Commit

Permalink
Optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Mar 14, 2024
1 parent 72070aa commit e4636ba
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
44 changes: 22 additions & 22 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ BenchTest:testMintPandora_13() (gas: 967960)
BenchTest:testMintPandora_14() (gas: 1037484)
BenchTest:testMintPandora_15() (gas: 1107011)
BenchTest:testMintPandora_16() (gas: 1176495)
BenchTest:test__codesize() (gas: 39359)
BenchTest:test__codesize() (gas: 39261)
DN404CustomUnitTest:testInitializeCorrectUnitSuccess() (gas: 129992)
DN404CustomUnitTest:testInitializeWithUnitTooLargeReverts() (gas: 33824)
DN404CustomUnitTest:testInitializeWithZeroUnitReverts() (gas: 13897)
Expand Down Expand Up @@ -177,37 +177,37 @@ DN404Test:test__codesize() (gas: 57768)
DN69OnlyERC20Test:testApprove() (gas: 35770)
DN69OnlyERC20Test:testApprove(address,uint256) (runs: 256, μ: 30077, ~: 31321)
DN69OnlyERC20Test:testBurn() (gas: 50088)
DN69OnlyERC20Test:testBurn(address,uint256,uint256) (runs: 256, μ: 51161, ~: 51289)
DN69OnlyERC20Test:testBurnInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 44301, ~: 44379)
DN69OnlyERC20Test:testBurn(address,uint256,uint256) (runs: 256, μ: 51131, ~: 51289)
DN69OnlyERC20Test:testBurnInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 44306, ~: 44370)
DN69OnlyERC20Test:testInfiniteApproveTransferFrom() (gas: 102308)
DN69OnlyERC20Test:testMaxSupplyTrick(uint256) (runs: 256, μ: 541, ~: 541)
DN69OnlyERC20Test:testMetadata() (gas: 10090)
DN69OnlyERC20Test:testMint() (gas: 45622)
DN69OnlyERC20Test:testMintOverMaxLimitReverts() (gas: 41669)
DN69OnlyERC20Test:testMintz(address,uint256) (runs: 256, μ: 46031, ~: 46044)
DN69OnlyERC20Test:testMintz(address,uint256) (runs: 256, μ: 45935, ~: 46044)
DN69OnlyERC20Test:testTransfer() (gas: 75015)
DN69OnlyERC20Test:testTransfer(address,uint256) (runs: 256, μ: 75457, ~: 75472)
DN69OnlyERC20Test:testTransfer(address,uint256) (runs: 256, μ: 75372, ~: 75472)
DN69OnlyERC20Test:testTransferFrom() (gas: 84766)
DN69OnlyERC20Test:testTransferFrom(address,address,address,uint256,uint256) (runs: 256, μ: 105516, ~: 107714)
DN69OnlyERC20Test:testTransferFrom(address,address,address,uint256,uint256) (runs: 256, μ: 105584, ~: 107714)
DN69OnlyERC20Test:testTransferFromInsufficientAllowanceReverts() (gas: 68344)
DN69OnlyERC20Test:testTransferFromInsufficientAllowanceReverts(address,uint256,uint256) (runs: 256, μ: 68955, ~: 69449)
DN69OnlyERC20Test:testTransferFromInsufficientAllowanceReverts(address,uint256,uint256) (runs: 256, μ: 68865, ~: 69454)
DN69OnlyERC20Test:testTransferFromInsufficientBalanceReverts() (gas: 75287)
DN69OnlyERC20Test:testTransferFromInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 76366, ~: 76417)
DN69OnlyERC20Test:testTransferFromInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 76270, ~: 76408)
DN69OnlyERC20Test:testTransferInsufficientBalanceReverts() (gas: 66753)
DN69OnlyERC20Test:testTransferInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 67959, ~: 67844)
DN69OnlyERC20Test:test__codesize() (gas: 27460)
DN69Test:testERC1155Methods(uint256) (runs: 256, μ: 4383637, ~: 4632589)
DN69Test:testERC1155MethodsSelfTransfers(uint256) (runs: 256, μ: 2399600, ~: 2081475)
DN69Test:testFindOwnedIds() (gas: 2671122)
DN69Test:testMintToNonERC155RecipientReverts(uint256) (runs: 256, μ: 951820, ~: 804567)
DN69Test:testMintToRevertingERC155RecipientReverts(uint256) (runs: 256, μ: 1488842, ~: 985654)
DN69Test:testMintToZeroReverts(uint256) (runs: 256, μ: 770240, ~: 670088)
DN69Test:testMixed(uint256) (runs: 256, μ: 8811163, ~: 6568105)
DN69Test:testSafeBatchTransferFromToERC1155Recipient(uint256) (runs: 256, μ: 2225548, ~: 2193790)
DN69Test:testSafeTransferFromToERC1155Recipient(uint256) (runs: 256, μ: 1737286, ~: 1481876)
DN69Test:testTransferFromToERC1155Recipient(uint256) (runs: 256, μ: 2890015, ~: 2878374)
DN69Test:testTransferMixedReverts(uint256) (runs: 256, μ: 3648867, ~: 2683685)
DN69Test:test__codesize() (gas: 62615)
DN69OnlyERC20Test:testTransferInsufficientBalanceReverts(address,uint256,uint256) (runs: 256, μ: 67784, ~: 67840)
DN69OnlyERC20Test:test__codesize() (gas: 27362)
DN69Test:testERC1155Methods(uint256) (runs: 256, μ: 4333900, ~: 4579672)
DN69Test:testERC1155MethodsSelfTransfers(uint256) (runs: 256, μ: 2391674, ~: 2061834)
DN69Test:testFindOwnedIds() (gas: 2644645)
DN69Test:testMintToNonERC155RecipientReverts(uint256) (runs: 256, μ: 955944, ~: 796373)
DN69Test:testMintToRevertingERC155RecipientReverts(uint256) (runs: 256, μ: 1430314, ~: 979013)
DN69Test:testMintToZeroReverts(uint256) (runs: 256, μ: 733644, ~: 663451)
DN69Test:testMixed(uint256) (runs: 256, μ: 9087516, ~: 6381628)
DN69Test:testSafeBatchTransferFromToERC1155Recipient(uint256) (runs: 256, μ: 2278331, ~: 2180026)
DN69Test:testSafeTransferFromToERC1155Recipient(uint256) (runs: 256, μ: 1773197, ~: 1475327)
DN69Test:testTransferFromToERC1155Recipient(uint256) (runs: 256, μ: 2878031, ~: 2865161)
DN69Test:testTransferMixedReverts(uint256) (runs: 256, μ: 3561882, ~: 2679134)
DN69Test:test__codesize() (gas: 62522)
MappingsTest:testAddressPairMapSetAndGet(address[2],address[2],uint256,uint256) (runs: 256, μ: 45753, ~: 47075)
MappingsTest:testBitmapSetAndGet(uint256) (runs: 256, μ: 445667, ~: 397521)
MappingsTest:testBitmapSetAndGet(uint256,uint256,bool,bool) (runs: 256, μ: 25662, ~: 26319)
Expand Down
14 changes: 7 additions & 7 deletions src/DN69.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1073,10 +1073,12 @@ abstract contract DN69 {
if (fnSelector == 0x2eb2c2d6) {
uint256[] memory ids = _calldataUint256Array(0x44);
unchecked {
uint256[] memory amounts = _calldataUint256Array(0x64);
uint256 amountsOffset = _calldataload(0x64) + 0x04;
uint256 n = ids.length;
if (n != amounts.length) revert ArrayLengthsMismatch();
while (n-- != 0) if (_get(amounts, n) != 1) revert InvalidNFTAmount();
if (n != _calldataload(amountsOffset)) revert ArrayLengthsMismatch();
for (uint256 o = amountsOffset + (n << 5); o != amountsOffset; o -= 0x20) {
if (_calldataload(o) != 1) revert InvalidNFTAmount();
}
}
_safeBatchTransferNFTs(
msg.sender,
Expand All @@ -1096,7 +1098,7 @@ abstract contract DN69 {
if (owners.length != n) revert ArrayLengthsMismatch();
uint256[] memory result = _idsMalloc(n);
while (n-- != 0) {
_set(result, n, _toUint(_get($.owned[_get(owners, n)], _get(ids, n))));
_set(result, n, _toUint(owns(_get(owners, n), _get(ids, n))));
}
/// @solidity memory-safe-assembly
assembly {
Expand All @@ -1107,9 +1109,7 @@ abstract contract DN69 {
}
// `balanceOf(address,uint256)`.
if (fnSelector == 0x00fdd58e) {
address owner = address(uint160(_calldataload(0x04)));
uint256 id = _calldataload(0x24);
_return(_toUint(_get($.owned[owner], id)));
_return(_toUint(owns(address(uint160(_calldataload(0x04))), _calldataload(0x24))));
}
// `implementsDN69()`.
if (fnSelector == 0x0e0b0984) {
Expand Down

0 comments on commit e4636ba

Please sign in to comment.