Skip to content

Commit 44a9963

Browse files
transmissions11z0r0zalephao0agejoshieDo
authored
✨ V6: First Production Release (#77)
Co-authored-by: t11s <[email protected]> Co-authored-by: z0r0z <[email protected]> Co-authored-by: alephao <[email protected]> Co-authored-by: 0age <[email protected]> Co-authored-by: joshieDo <[email protected]> Co-authored-by: Matt <[email protected]> Co-authored-by: Andreas Bigger <[email protected]> Co-authored-by: Ryan <[email protected]> Co-authored-by: Zefram Lou <[email protected]> Co-authored-by: RagePit <[email protected]>
1 parent fab1075 commit 44a9963

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+4836
-553
lines changed

.gas-snapshot

+140-33
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,151 @@
1-
testAcceptingOwner() (gas: 139707)
2-
testFailNonOwner2() (gas: 3773)
3-
testFailRejectingAuthority1() (gas: 119902)
4-
testFailNonOwner1() (gas: 3742)
5-
testFailRejectingAuthority2() (gas: 119999)
1+
testFailSetAuthorityWithRestrictiveAuthority() (gas: 126002)
2+
testSetAuthorityWithPermissiveAuthority() (gas: 127687)
3+
testFailSetOwnerWithRestrictiveAuthority() (gas: 126166)
4+
testFailCallFunctionAsNonOwner() (gas: 4191)
5+
testSetAuthorityAsOwner() (gas: 23802)
6+
testFailCallFunctionAsOwnerWithOutOfOrderAuthority() (gas: 135733)
7+
testCallFunctionWithPermissiveAuthority() (gas: 125973)
8+
testFailSetAuthorityAsNonOwner() (gas: 6960)
9+
testFailSetOwnerAsOwnerWithOutOfOrderAuthority() (gas: 135873)
10+
testCallFunctionAsOwner() (gas: 21371)
11+
testFailCallFunctionWithRestrictiveAuthority() (gas: 126125)
12+
testSetOwnerWithPermissiveAuthority() (gas: 147508)
13+
testFailSetOwnerAsNonOwner() (gas: 4309)
14+
testSetAuthorityAsOwnerWithOutOfOrderAuthority() (gas: 234329)
15+
testSetOwnerAsOwner() (gas: 3998)
616
testFromLast20Bytes() (gas: 191)
717
testFillLast12Bytes() (gas: 223)
8-
testFailDoubleDeploySameBytecode() (gas: 277076930206519)
9-
testDeployERC20() (gas: 885671)
10-
testFailDoubleDeployDifferentBytecode() (gas: 277076930206511)
11-
testMin() (gas: 715)
12-
testFPow() (gas: 1738)
13-
testMax() (gas: 757)
14-
testFailFDivZeroXY() (gas: 298)
15-
testSqrt() (gas: 2342)
16-
testFDiv() (gas: 764)
17-
testFDivEdgeCases() (gas: 543)
18-
testFMulEdgeCases() (gas: 823)
19-
testFailFDivXYB() (gas: 319)
20-
testFailFDivZeroY() (gas: 274)
18+
testFailDoubleDeploySameBytecode() (gas: 277076930206699)
19+
testDeployERC20() (gas: 873896)
20+
testFailDoubleDeployDifferentBytecode() (gas: 277076930214885)
21+
testFailBoundMinBiggerThanMax() (gas: 309)
22+
testBound() (gas: 5520)
23+
testFailSafeBatchTransferFromToRevertingERC1155Recipient() (gas: 1041163)
24+
testMintToEOA() (gas: 30265)
25+
testFailMintToNonERC155Recipient() (gas: 71897)
26+
testFailSafeBatchTransferFromToZero() (gas: 805864)
27+
testBatchMintToERC1155Recipient() (gas: 946375)
28+
testApproveAll() (gas: 26509)
29+
testFailSafeBatchTransferFromWithArrayLengthMismatch() (gas: 681042)
30+
testFailBatchMintToZero() (gas: 127242)
31+
testFailSafeBatchTransferFromToWrongReturnDataERC1155Recipient() (gas: 993087)
32+
testSafeTransferFromToERC1155Recipient() (gas: 1210543)
33+
testFailBatchMintToWrongReturnDataERC1155Recipient() (gas: 314473)
34+
testFailBatchMintToRevertingERC1155Recipient() (gas: 362536)
35+
testBatchBurn() (gas: 146591)
36+
testFailBurnInsufficientBalance() (gas: 30352)
37+
testFailSafeTransferFromToWrongReturnDataERC1155Recipient() (gas: 243471)
38+
testFailMintToRevertingERC155Recipient() (gas: 263148)
39+
testFailSafeBatchTransferFromToNonERC1155Recipient() (gas: 849621)
40+
testFailSafeTransferFromInsufficientBalance() (gas: 579173)
41+
testFailSafeTransferFromToNonERC155Recipient() (gas: 100376)
42+
testFailBatchMintToNonERC1155Recipient() (gas: 171010)
43+
testSafeBatchTransferFromToEOA() (gas: 817122)
44+
testFailSafeTransferFromToRevertingERC1155Recipient() (gas: 291604)
45+
testBatchMintToEOA() (gas: 132842)
46+
testFailBatchBurnInsufficientBalance() (gas: 131673)
47+
testSafeBatchTransferFromToERC1155Recipient() (gas: 1650504)
48+
testFailBalanceOfBatchWithArrayMismatch() (gas: 4798)
49+
testFailSafeBatchTransferInsufficientBalance() (gas: 682003)
50+
testSafeTransferFromToEOA() (gas: 609087)
51+
testMintToERC1155Recipient() (gas: 612041)
52+
testFailBatchMintWithArrayMismatch() (gas: 5118)
53+
testBatchBalanceOf() (gas: 153798)
54+
testFailSafeTransferFromToZero() (gas: 57667)
55+
testFailSafeTransferFromSelfInsufficientBalance() (gas: 29956)
56+
testBurn() (gas: 34098)
57+
testFailBatchBurnWithArrayLengthMismatch() (gas: 131065)
58+
testFailMintToZero() (gas: 29205)
59+
testSafeTransferFromSelf() (gas: 59828)
60+
testFailMintToWrongReturnDataERC155Recipient() (gas: 263102)
61+
testInfiniteApproveTransferFrom() (gas: 387796)
62+
testApprove() (gas: 26558)
63+
testMetaData() (gas: 6966)
64+
testTransferFrom() (gas: 388134)
65+
testFailTransferFromInsufficientBalance() (gas: 359401)
66+
testFailPermitPastDeadline() (gas: 2197)
67+
testFailPermitReplay() (gas: 59949)
68+
testMint() (gas: 49180)
69+
testFailTransferFromInsufficientAllowance() (gas: 358925)
70+
testTransfer() (gas: 75628)
71+
testBurn() (gas: 52492)
72+
testPermit() (gas: 56782)
73+
testFailTransferInsufficientBalance() (gas: 48240)
74+
testFailPermitBadDeadline() (gas: 30486)
75+
testFailPermitBadNonce() (gas: 30436)
76+
testSafeTransferFromToERC721Recipient() (gas: 908869)
77+
testFailSafeMintToERC721RecipientWithWrongReturnDataWithData() (gas: 185732)
78+
testApprove() (gas: 96031)
79+
testFailBurnUnMinted() (gas: 3379)
80+
testFailSafeTransferFromToERC721RecipientWithWrongReturnDataWithData() (gas: 213867)
81+
testFailDoubleMint() (gas: 70935)
82+
testApproveAll() (gas: 26585)
83+
testFailApproveUnAuthorized() (gas: 73181)
84+
testFailSafeTransferFromToRevertingERC721RecipientWithData() (gas: 259577)
85+
testFailSafeMintToNonERC721RecipientWithData() (gas: 115867)
86+
testMetadata() (gas: 6492)
87+
testFailTransferFromWrongFrom() (gas: 71032)
88+
testFailSafeMintToRevertingERC721Recipient() (gas: 230626)
89+
testTransferFrom() (gas: 551359)
90+
testFailSafeMintToNonERC721Recipient() (gas: 115042)
91+
testFailDoubleBurn() (gas: 74563)
92+
testFailSafeMintToERC721RecipientWithWrongReturnData() (gas: 184893)
93+
testFailSafeTransferFromToNonERC721Recipient() (gas: 143245)
94+
testMint() (gas: 72701)
95+
testFailApproveUnMinted() (gas: 5694)
96+
testFailTransferFromToZero() (gas: 71031)
97+
testSafeMintToERC721Recipient() (gas: 408375)
98+
testSafeTransferFromToEOA() (gas: 556215)
99+
testSafeMintToEOA() (gas: 75400)
100+
testFailSafeTransferFromToERC721RecipientWithWrongReturnData() (gas: 213093)
101+
testTransferFromApproveAll() (gas: 553534)
102+
testFailTransferFromUnOwned() (gas: 3500)
103+
testFailSafeTransferFromToNonERC721RecipientWithData() (gas: 144048)
104+
testBurn() (gas: 76417)
105+
testFailSafeMintToRevertingERC721RecipientWithData() (gas: 231396)
106+
testFailMintToZero() (gas: 1253)
107+
testFailTransferFromNotOwner() (gas: 75544)
108+
testSafeMintToERC721RecipientWithData() (gas: 429537)
109+
testFailSafeTransferFromToRevertingERC721Recipient() (gas: 258848)
110+
testSafeTransferFromToERC721RecipientWithData() (gas: 930031)
111+
testTransferFromSelf() (gas: 103082)
112+
testFPow() (gas: 1651)
113+
testFailFDivZeroXY() (gas: 316)
114+
testSqrt() (gas: 2492)
115+
testFDiv() (gas: 733)
116+
testFDivEdgeCases() (gas: 581)
117+
testFMulEdgeCases() (gas: 801)
118+
testFailFDivXYB() (gas: 294)
119+
testFailFDivZeroY() (gas: 271)
21120
testFMul() (gas: 669)
121+
testSetRoles() (gas: 33023)
122+
testCanCallWithCustomAuthorityOverridesPublicCapability() (gas: 295417)
123+
testCanCallPublicCapability() (gas: 39631)
124+
testSetTargetCustomAuthority() (gas: 31736)
125+
testCanCallWithCustomAuthorityOverridesUserWithRole() (gas: 334265)
126+
testCanCallWithAuthorizedRole() (gas: 97461)
127+
testSetRoleCapabilities() (gas: 32997)
128+
testCanCallWithCustomAuthority() (gas: 466959)
129+
testSetPublicCapabilities() (gas: 31468)
22130
testNoReentrancy() (gas: 1015)
23131
testProtectedCall() (gas: 23649)
24132
testFailUnprotectedCall() (gas: 30515)
25-
testBasics() (gas: 76765)
26-
testRoot() (gas: 40181)
27-
testSanityChecks() (gas: 11630)
28-
testPublicCapabilities() (gas: 41708)
29-
testWriteRead() (gas: 53564)
30-
testWriteReadFullStartBound() (gas: 34778)
31-
testFailWriteReadEmptyOutOfBounds() (gas: 34479)
32-
testWriteReadFullBoundedRead() (gas: 53761)
133+
testSetRoles() (gas: 32998)
134+
testCanCallPublicCapability() (gas: 38436)
135+
testCanCallWithAuthorizedRole() (gas: 96267)
136+
testSetRoleCapabilities() (gas: 34588)
137+
testSetPublicCapabilities() (gas: 33244)
138+
testWriteRead() (gas: 53511)
139+
testWriteReadFullStartBound() (gas: 34725)
140+
testFailWriteReadEmptyOutOfBounds() (gas: 34432)
141+
testWriteReadFullBoundedRead() (gas: 53708)
33142
testFailReadInvalidPointer() (gas: 2905)
34-
testFailWriteReadOutOfStartBound() (gas: 34393)
143+
testFailWriteReadOutOfStartBound() (gas: 34346)
35144
testFailReadInvalidPointerCustomStartBound() (gas: 2982)
36-
testWriteReadEmptyBound() (gas: 34692)
37-
testFailWriteReadOutOfBounds() (gas: 34500)
38-
testWriteReadCustomBounds() (gas: 34906)
39-
testWriteReadCustomStartBound() (gas: 34821)
145+
testWriteReadEmptyBound() (gas: 34639)
146+
testFailWriteReadOutOfBounds() (gas: 34453)
147+
testWriteReadCustomBounds() (gas: 34853)
148+
testWriteReadCustomStartBound() (gas: 34768)
40149
testFailReadInvalidPointerCustomBounds() (gas: 3143)
41150
testSafeCastTo248() (gas: 433)
42151
testSafeCastTo128() (gas: 455)
@@ -68,8 +177,6 @@ testTransferWithNonContract() (gas: 3075)
68177
testApproveWithTransferFromSelf() (gas: 26416)
69178
testTransferWithTransferFromSelf() (gas: 28182)
70179
testFailTransferETHToContractWithoutFallback() (gas: 7222)
71-
testUpdateTrust() (gas: 12713)
72-
testSanityChecks() (gas: 4838)
73180
testPartialWithdraw() (gas: 68803)
74181
testDeposit() (gas: 58804)
75182
testFallbackDeposit() (gas: 59068)

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
/out
2-
/node_modules
1+
/cache
2+
/node_modules
3+
/out

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
```ml
88
auth
99
├─ Auth — "Flexible and updatable auth pattern"
10-
├─ Trust — "Ultra minimal authorization logic"
1110
├─ authorities
1211
│ ├─ RolesAuthority — "Role based Authority that supports up to 256 roles"
13-
│ ├─ TrustAuthority — "Simple Authority which only authorizes trusted users"
12+
│ ├─ MultiRolesAuthority — "Flexible and target agnostic role based Authority"
1413
tokens
1514
├─ WETH — "Minimalist and modern Wrapped Ether implementation"
1615
├─ ERC20 — "Modern and gas efficient ERC20 + EIP-2612 implementation"
16+
├─ ERC721 — "Modern, minimalist, and gas efficient ERC721 implementation"
17+
├─ ERC1155 — "Minimalist and gas efficient standard ERC1155 implementation"
1718
utils
1819
├─ SSTORE2 - "Library for cheaper reads and writes to persistent storage"
1920
├─ CREATE3 — "Deploy to deterministic addresses without an initcode factor"

audits/v6-Fixed-Point-Solutions.pdf

166 KB
Binary file not shown.

src/auth/Auth.sol

+34-32
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,13 @@
11
// SPDX-License-Identifier: AGPL-3.0-only
2-
pragma solidity >=0.7.0;
3-
4-
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
5-
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
6-
interface Authority {
7-
function canCall(
8-
address user,
9-
address target,
10-
bytes4 functionSig
11-
) external view returns (bool);
12-
}
2+
pragma solidity >=0.8.0;
133

144
/// @notice Provides a flexible and updatable auth pattern which is completely separate from application logic.
5+
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Auth.sol)
156
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
167
abstract contract Auth {
17-
event OwnerUpdated(address indexed owner);
8+
event OwnerUpdated(address indexed user, address indexed newOwner);
189

19-
event AuthorityUpdated(Authority indexed authority);
10+
event AuthorityUpdated(address indexed user, Authority indexed newAuthority);
2011

2112
address public owner;
2213

@@ -26,37 +17,48 @@ abstract contract Auth {
2617
owner = _owner;
2718
authority = _authority;
2819

29-
emit OwnerUpdated(_owner);
30-
emit AuthorityUpdated(_authority);
20+
emit OwnerUpdated(msg.sender, _owner);
21+
emit AuthorityUpdated(msg.sender, _authority);
3122
}
3223

33-
function setOwner(address newOwner) public virtual requiresAuth {
34-
owner = newOwner;
24+
modifier requiresAuth() {
25+
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
3526

36-
emit OwnerUpdated(owner);
27+
_;
3728
}
3829

39-
function setAuthority(Authority newAuthority) public virtual requiresAuth {
40-
authority = newAuthority;
30+
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
31+
Authority auth = authority; // Memoizing authority saves us a warm SLOAD, around 100 gas.
4132

42-
emit AuthorityUpdated(authority);
33+
// Checking if the caller is the owner only after calling the authority saves gas in most cases, but be
34+
// aware that this makes protected functions uncallable even to the owner if the authority is out of order.
35+
return (address(auth) != address(0) && auth.canCall(user, address(this), functionSig)) || user == owner;
4336
}
4437

45-
function isAuthorized(address user, bytes4 functionSig) internal view virtual returns (bool) {
46-
Authority cachedAuthority = authority;
38+
function setAuthority(Authority newAuthority) public virtual {
39+
// We check if the caller is the owner first because we want to ensure they can
40+
// always swap out the authority even if it's reverting or using up a lot of gas.
41+
require(msg.sender == owner || authority.canCall(msg.sender, address(this), msg.sig));
4742

48-
if (address(cachedAuthority) != address(0)) {
49-
try cachedAuthority.canCall(user, address(this), functionSig) returns (bool canCall) {
50-
if (canCall) return true;
51-
} catch {}
52-
}
43+
authority = newAuthority;
5344

54-
return user == owner;
45+
emit AuthorityUpdated(msg.sender, newAuthority);
5546
}
5647

57-
modifier requiresAuth() {
58-
require(isAuthorized(msg.sender, msg.sig), "UNAUTHORIZED");
48+
function setOwner(address newOwner) public virtual requiresAuth {
49+
owner = newOwner;
5950

60-
_;
51+
emit OwnerUpdated(msg.sender, newOwner);
6152
}
6253
}
54+
55+
/// @notice A generic interface for a contract which provides authorization data to an Auth instance.
56+
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/auth/Auth.sol)
57+
/// @author Modified from Dappsys (https://github.com/dapphub/ds-auth/blob/master/src/auth.sol)
58+
interface Authority {
59+
function canCall(
60+
address user,
61+
address target,
62+
bytes4 functionSig
63+
) external view returns (bool);
64+
}

src/auth/Trust.sol

-28
This file was deleted.

0 commit comments

Comments
 (0)