Skip to content

Commit

Permalink
Merge pull request Sol-DAO#69 from Sol-DAO/erc1155b
Browse files Browse the repository at this point in the history
✨ ERC1155B
  • Loading branch information
z0r0z authored Nov 16, 2022
2 parents 09b6ce4 + e38510e commit 2572d3a
Show file tree
Hide file tree
Showing 6 changed files with 1,105 additions and 47 deletions.
120 changes: 78 additions & 42 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,29 @@ EIP712Test:testDigest() (gas: 12916)
ERC1155Test:testApproveAll() (gas: 30986)
ERC1155Test:testApproveAll(address,bool) (runs: 256, μ: 16849, ~: 11417)
ERC1155Test:testBatchBalanceOf() (gas: 157423)
ERC1155Test:testBatchBalanceOf(address[],uint256[],uint256[],bytes) (runs: 256, μ: 3305275, ~: 2594045)
ERC1155Test:testBatchBalanceOf(address[],uint256[],uint256[],bytes) (runs: 256, μ: 3305324, ~: 2594045)
ERC1155Test:testBatchBurn() (gas: 151176)
ERC1155Test:testBatchBurn(address,uint256[],uint256[],uint256[],bytes) (runs: 256, μ: 3457909, ~: 3062676)
ERC1155Test:testBatchBurn(address,uint256[],uint256[],uint256[],bytes) (runs: 256, μ: 3454382, ~: 3061084)
ERC1155Test:testBatchMintToEOA() (gas: 137377)
ERC1155Test:testBatchMintToEOA(address,uint256[],uint256[],bytes) (runs: 256, μ: 3265687, ~: 2944287)
ERC1155Test:testBatchMintToEOA(address,uint256[],uint256[],bytes) (runs: 256, μ: 3268753, ~: 2944287)
ERC1155Test:testBatchMintToERC1155Recipient() (gas: 994281)
ERC1155Test:testBatchMintToERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 7335949, ~: 6374701)
ERC1155Test:testBatchMintToERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 7336833, ~: 6396501)
ERC1155Test:testBurn() (gas: 38582)
ERC1155Test:testBurn(address,uint256,uint256,bytes,uint256) (runs: 256, μ: 40155, ~: 42088)
ERC1155Test:testBurn(address,uint256,uint256,bytes,uint256) (runs: 256, μ: 40205, ~: 42088)
ERC1155Test:testFailBalanceOfBatchWithArrayMismatch() (gas: 7880)
ERC1155Test:testFailBalanceOfBatchWithArrayMismatch(address[],uint256[]) (runs: 256, μ: 53333, ~: 54013)
ERC1155Test:testFailBatchBurnInsufficientBalance() (gas: 136224)
ERC1155Test:testFailBatchBurnInsufficientBalance(address,uint256[],uint256[],uint256[],bytes) (runs: 256, μ: 1281911, ~: 441110)
ERC1155Test:testFailBatchBurnInsufficientBalance(address,uint256[],uint256[],uint256[],bytes) (runs: 256, μ: 1279357, ~: 441110)
ERC1155Test:testFailBatchBurnWithArrayLengthMismatch() (gas: 135529)
ERC1155Test:testFailBatchBurnWithArrayLengthMismatch(address,uint256[],uint256[],uint256[],bytes) (runs: 256, μ: 77061, ~: 78670)
ERC1155Test:testFailBatchMintToNonERC1155Recipient() (gas: 167341)
ERC1155Test:testFailBatchMintToNonERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 3133059, ~: 2675353)
ERC1155Test:testFailBatchMintToNonERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 3133943, ~: 2675353)
ERC1155Test:testFailBatchMintToRevertingERC1155Recipient() (gas: 357438)
ERC1155Test:testFailBatchMintToRevertingERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 3323175, ~: 2865467)
ERC1155Test:testFailBatchMintToRevertingERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 3324058, ~: 2865467)
ERC1155Test:testFailBatchMintToWrongReturnDataERC1155Recipient() (gas: 310714)
ERC1155Test:testFailBatchMintToWrongReturnDataERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 3276477, ~: 2818770)
ERC1155Test:testFailBatchMintToWrongReturnDataERC1155Recipient(uint256[],uint256[],bytes) (runs: 256, μ: 3277360, ~: 2818770)
ERC1155Test:testFailBatchMintToZero() (gas: 131711)
ERC1155Test:testFailBatchMintToZero(uint256[],uint256[],bytes) (runs: 256, μ: 3073494, ~: 2614560)
ERC1155Test:testFailBatchMintToZero(uint256[],uint256[],bytes) (runs: 256, μ: 3074378, ~: 2614560)
ERC1155Test:testFailBatchMintWithArrayMismatch() (gas: 9547)
ERC1155Test:testFailBatchMintWithArrayMismatch(address,uint256[],uint256[],bytes) (runs: 256, μ: 69176, ~: 68740)
ERC1155Test:testFailBurnInsufficientBalance() (gas: 34834)
Expand All @@ -111,44 +111,80 @@ ERC1155Test:testFailMintToWrongReturnDataERC155Recipient() (gas: 257930)
ERC1155Test:testFailMintToWrongReturnDataERC155Recipient(uint256,uint256,bytes) (runs: 256, μ: 258210, ~: 258892)
ERC1155Test:testFailMintToZero() (gas: 33587)
ERC1155Test:testFailMintToZero(uint256,uint256,bytes) (runs: 256, μ: 33676, ~: 34406)
ERC1155Test:testFailSafeBatchTransferFromToNonERC1155Recipient() (gas: 321547)
ERC1155Test:testFailSafeBatchTransferFromToNonERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3498217, ~: 2963179)
ERC1155Test:testFailSafeBatchTransferFromToRevertingERC1155Recipient() (gas: 511704)
ERC1155Test:testFailSafeBatchTransferFromToRevertingERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3688332, ~: 3153288)
ERC1155Test:testFailSafeBatchTransferFromToWrongReturnDataERC1155Recipient() (gas: 464939)
ERC1155Test:testFailSafeBatchTransferFromToWrongReturnDataERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3641594, ~: 3106553)
ERC1155Test:testFailSafeBatchTransferFromToZero() (gas: 286668)
ERC1155Test:testFailSafeBatchTransferFromToZero(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3462979, ~: 2928024)
ERC1155Test:testFailSafeBatchTransferFromToNonERC1155Recipient() (gas: 321529)
ERC1155Test:testFailSafeBatchTransferFromToNonERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3501826, ~: 2966443)
ERC1155Test:testFailSafeBatchTransferFromToRevertingERC1155Recipient() (gas: 511686)
ERC1155Test:testFailSafeBatchTransferFromToRevertingERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3691941, ~: 3156552)
ERC1155Test:testFailSafeBatchTransferFromToWrongReturnDataERC1155Recipient() (gas: 464921)
ERC1155Test:testFailSafeBatchTransferFromToWrongReturnDataERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3645203, ~: 3109817)
ERC1155Test:testFailSafeBatchTransferFromToZero() (gas: 286650)
ERC1155Test:testFailSafeBatchTransferFromToZero(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 3466588, ~: 2931230)
ERC1155Test:testFailSafeBatchTransferFromWithArrayLengthMismatch() (gas: 162739)
ERC1155Test:testFailSafeBatchTransferFromWithArrayLengthMismatch(address,uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 81109, ~: 81961)
ERC1155Test:testFailSafeBatchTransferInsufficientBalance() (gas: 163702)
ERC1155Test:testFailSafeBatchTransferInsufficientBalance(address,uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 1499863, ~: 500326)
ERC1155Test:testFailSafeTransferFromInsufficientBalance() (gas: 63261)
ERC1155Test:testFailSafeTransferFromInsufficientBalance(address,uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 63977, ~: 67392)
ERC1155Test:testFailSafeTransferFromSelfInsufficientBalance() (gas: 34297)
ERC1155Test:testFailSafeTransferFromSelfInsufficientBalance(address,uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 36227, ~: 38462)
ERC1155Test:testFailSafeTransferFromToNonERC155Recipient() (gas: 96517)
ERC1155Test:testFailSafeTransferFromToNonERC155Recipient(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 96619, ~: 100533)
ERC1155Test:testFailSafeTransferFromToRevertingERC1155Recipient() (gas: 286316)
ERC1155Test:testFailSafeTransferFromToRevertingERC1155Recipient(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 286367, ~: 290281)
ERC1155Test:testFailSafeTransferFromToWrongReturnDataERC1155Recipient() (gas: 239516)
ERC1155Test:testFailSafeTransferFromToWrongReturnDataERC1155Recipient(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 239590, ~: 243504)
ERC1155Test:testFailSafeTransferFromToZero() (gas: 61942)
ERC1155Test:testFailSafeTransferFromToZero(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 62029, ~: 65945)
ERC1155Test:testFailSafeBatchTransferInsufficientBalance() (gas: 163684)
ERC1155Test:testFailSafeBatchTransferInsufficientBalance(address,uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 1501898, ~: 500326)
ERC1155Test:testFailSafeTransferFromInsufficientBalance() (gas: 63243)
ERC1155Test:testFailSafeTransferFromInsufficientBalance(address,uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 63960, ~: 67374)
ERC1155Test:testFailSafeTransferFromSelfInsufficientBalance() (gas: 34271)
ERC1155Test:testFailSafeTransferFromSelfInsufficientBalance(address,uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 36202, ~: 38436)
ERC1155Test:testFailSafeTransferFromToNonERC155Recipient() (gas: 96491)
ERC1155Test:testFailSafeTransferFromToNonERC155Recipient(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 96593, ~: 100507)
ERC1155Test:testFailSafeTransferFromToRevertingERC1155Recipient() (gas: 286290)
ERC1155Test:testFailSafeTransferFromToRevertingERC1155Recipient(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 286341, ~: 290255)
ERC1155Test:testFailSafeTransferFromToWrongReturnDataERC1155Recipient() (gas: 239490)
ERC1155Test:testFailSafeTransferFromToWrongReturnDataERC1155Recipient(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 239564, ~: 243478)
ERC1155Test:testFailSafeTransferFromToZero() (gas: 61916)
ERC1155Test:testFailSafeTransferFromToZero(uint256,uint256,uint256,bytes,bytes) (runs: 256, μ: 62003, ~: 65919)
ERC1155Test:testMintToEOA() (gas: 34719)
ERC1155Test:testMintToEOA(address,uint256,uint256,bytes) (runs: 256, μ: 35359, ~: 35839)
ERC1155Test:testMintToERC1155Recipient() (gas: 659903)
ERC1155Test:testMintToERC1155Recipient(uint256,uint256,bytes) (runs: 256, μ: 689586, ~: 682903)
ERC1155Test:testSafeBatchTransferFromToEOA() (gas: 298000)
ERC1155Test:testSafeBatchTransferFromToEOA(address,uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 4697311, ~: 3744489)
ERC1155Test:testSafeBatchTransferFromToERC1155Recipient() (gas: 1174050)
ERC1155Test:testSafeBatchTransferFromToERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 7688971, ~: 6517171)
ERC1155Test:testSafeTransferFromSelf() (gas: 64177)
ERC1155Test:testSafeTransferFromSelf(uint256,uint256,bytes,uint256,address,bytes) (runs: 256, μ: 64711, ~: 68552)
ERC1155Test:testSafeTransferFromToEOA() (gas: 93183)
ERC1155Test:testSafeTransferFromToEOA(uint256,uint256,bytes,uint256,address,bytes) (runs: 256, μ: 93494, ~: 97454)
ERC1155Test:testSafeTransferFromToERC1155Recipient() (gas: 738159)
ERC1155Test:testSafeTransferFromToERC1155Recipient(uint256,uint256,bytes,uint256,bytes) (runs: 256, μ: 768159, ~: 764321)
ERC1155Test:testSafeBatchTransferFromToEOA() (gas: 297982)
ERC1155Test:testSafeBatchTransferFromToEOA(address,uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 4701420, ~: 3744055)
ERC1155Test:testSafeBatchTransferFromToERC1155Recipient() (gas: 1174032)
ERC1155Test:testSafeBatchTransferFromToERC1155Recipient(uint256[],uint256[],uint256[],bytes,bytes) (runs: 256, μ: 7695348, ~: 6560852)
ERC1155Test:testSafeTransferFromSelf() (gas: 64151)
ERC1155Test:testSafeTransferFromSelf(uint256,uint256,bytes,uint256,address,bytes) (runs: 256, μ: 64685, ~: 68526)
ERC1155Test:testSafeTransferFromToEOA() (gas: 93165)
ERC1155Test:testSafeTransferFromToEOA(uint256,uint256,bytes,uint256,address,bytes) (runs: 256, μ: 93476, ~: 97436)
ERC1155Test:testSafeTransferFromToERC1155Recipient() (gas: 738141)
ERC1155Test:testSafeTransferFromToERC1155Recipient(uint256,uint256,bytes,uint256,bytes) (runs: 256, μ: 767986, ~: 764303)
ERC1155BTest:testApproveAll() (gas: 30991)
ERC1155BTest:testBatchBalanceOf() (gas: 156936)
ERC1155BTest:testBatchBurn() (gas: 114495)
ERC1155BTest:testBatchMintToEOA() (gas: 135777)
ERC1155BTest:testBatchMintToERC1155Recipient() (gas: 993173)
ERC1155BTest:testBurn() (gas: 26484)
ERC1155BTest:testFailBalanceOfBatchWithArrayMismatch() (gas: 7814)
ERC1155BTest:testFailBatchBurnInsufficientBalance() (gas: 9999)
ERC1155BTest:testFailBatchMintToNonERC1155Recipient() (gas: 166047)
ERC1155BTest:testFailBatchMintToRevertingERC1155Recipient() (gas: 356186)
ERC1155BTest:testFailBatchMintToWrongReturnDataERC1155Recipient() (gas: 309446)
ERC1155BTest:testFailBatchMintToZero() (gas: 30897)
ERC1155BTest:testFailBurnInsufficientBalance() (gas: 7715)
ERC1155BTest:testFailMintToNonERC1155Recipient() (gas: 68174)
ERC1155BTest:testFailMintToRevertingERC1155Recipient() (gas: 257955)
ERC1155BTest:testFailMintToWrongReturnDataERC1155Recipient() (gas: 257954)
ERC1155BTest:testFailMintToZero() (gas: 13642)
ERC1155BTest:testFailSafeBatchTransferFromToNonERC1155Recipient() (gas: 720974)
ERC1155BTest:testFailSafeBatchTransferFromToRevertingERC1155Recipient() (gas: 911045)
ERC1155BTest:testFailSafeBatchTransferFromToWrongReturnDataERC1155Recipient() (gas: 864349)
ERC1155BTest:testFailSafeBatchTransferFromToZero() (gas: 686073)
ERC1155BTest:testFailSafeBatchTransferFromWithArrayLengthMismatch() (gas: 673475)
ERC1155BTest:testFailSafeBatchTransferInsufficientBalance() (gas: 550651)
ERC1155BTest:testFailSafeTransferFromInsufficientBalance() (gas: 548032)
ERC1155BTest:testFailSafeTransferFromSelfInsufficientBalance() (gas: 8311)
ERC1155BTest:testFailSafeTransferFromToNonERC1155Recipient() (gas: 74183)
ERC1155BTest:testFailSafeTransferFromToRevertingERC1155Recipient() (gas: 263961)
ERC1155BTest:testFailSafeTransferFromToWrongReturnDataERC1155Recipient() (gas: 217205)
ERC1155BTest:testFailSafeTransferFromToZero() (gas: 8292)
ERC1155BTest:testMintToEOA() (gas: 34590)
ERC1155BTest:testMintToERC1155Recipient() (gas: 659786)
ERC1155BTest:testSafeBatchTransferFromToEOA() (gas: 696833)
ERC1155BTest:testSafeBatchTransferFromToERC1155Recipient() (gas: 1572647)
ERC1155BTest:testSafeTransferFromSelf() (gas: 41752)
ERC1155BTest:testSafeTransferFromToEOA() (gas: 581441)
ERC1155BTest:testSafeTransferFromToERC1155Recipient() (gas: 1226190)
ERC1155PermitTest:testFailPermitBadDeadline() (gas: 65971)
ERC1155PermitTest:testFailPermitBadDeadline(uint248,uint256,address) (runs: 256, μ: 66918, ~: 66918)
ERC1155PermitTest:testFailPermitBadNonce() (gas: 65933)
Expand Down
12 changes: 7 additions & 5 deletions src/tokens/ERC1155/ERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ abstract contract ERC1155 {
uint256 amount,
bytes calldata data
) public virtual {
if (msg.sender != from && !isApprovedForAll[from][msg.sender]) revert Unauthorized();
if (msg.sender != from)
if (!isApprovedForAll[from][msg.sender]) revert Unauthorized();

balanceOf[from][id] -= amount;
balanceOf[to][id] += amount;
Expand All @@ -96,7 +97,8 @@ abstract contract ERC1155 {
) public virtual {
if (ids.length != amounts.length) revert LengthMismatch();

if (msg.sender != from && !isApprovedForAll[from][msg.sender]) revert Unauthorized();
if (msg.sender != from)
if (!isApprovedForAll[from][msg.sender]) revert Unauthorized();

// Storing these outside the loop saves ~15 gas per iteration.
uint256 id;
Expand Down Expand Up @@ -149,9 +151,9 @@ abstract contract ERC1155 {

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155
interfaceId == 0x0e89341c; // ERC165 Interface ID for ERC1155MetadataURI
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165.
interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155.
interfaceId == 0x0e89341c; // ERC165 Interface ID for ERC1155MetadataURI.
}

/// -----------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 2572d3a

Please sign in to comment.