Skip to content

Commit

Permalink
Merge pull request #19 from NaniDAO/cattin/immutable-variables
Browse files Browse the repository at this point in the history
add immutable variables
  • Loading branch information
gcattinp authored Aug 29, 2024
2 parents af72b76 + 67594fb commit e8688d4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 36 deletions.
38 changes: 19 additions & 19 deletions .gas-snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ AccountTest:testCdFallback2() (gas: 1250652)
AccountTest:testDelegateExecute() (gas: 405036)
AccountTest:testDelegateExecute(uint256) (runs: 256, μ: 394834, ~: 384516)
AccountTest:testDelegateExecuteRevertsIfOwnerSlotValueChanged() (gas: 360183)
AccountTest:testDepositFunctions() (gas: 533677)
AccountTest:testDepositFunctions() (gas: 533572)
AccountTest:testDirectStorage() (gas: 70166)
AccountTest:testDisableInitializerForImplementation() (gas: 1522237)
AccountTest:testETHReceived() (gas: 16591)
AccountTest:testExecute() (gas: 422663)
AccountTest:testExecute() (gas: 422406)
AccountTest:testExecuteBatch() (gas: 773653)
AccountTest:testInitializer() (gas: 1804094)
AccountTest:testIsValidSignature() (gas: 119393)
AccountTest:testIsValidSignatureViaPlugin() (gas: 98455)
AccountTest:testIsValidSignatureViaRPC() (gas: 1040431688)
AccountTest:testIsValidSignatureWrapped() (gas: 452833)
AccountTest:testOnERC1155BatchReceived() (gas: 1573496)
AccountTest:testOnERC1155Received() (gas: 1570864)
AccountTest:testOnERC721Received() (gas: 1693476)
AccountTest:testOwnerRecovery() (gas: 516827)
AccountTest:testSignaturePluginStorage() (gas: 86831)
AccountTest:testValidateUserOp() (gas: 525722)
AccountTest:test__codesize() (gas: 67295)
AccountTest:testInitializer() (gas: 1803889)
AccountTest:testIsValidSignature() (gas: 119314)
AccountTest:testIsValidSignatureViaPlugin() (gas: 98376)
AccountTest:testIsValidSignatureViaRPC() (gas: 1040431685)
AccountTest:testIsValidSignatureWrapped() (gas: 452620)
AccountTest:testOnERC1155BatchReceived() (gas: 1491113)
AccountTest:testOnERC1155Received() (gas: 1490765)
AccountTest:testOnERC721Received() (gas: 1509738)
AccountTest:testOwnerRecovery() (gas: 516596)
AccountTest:testSignaturePluginStorage() (gas: 86434)
AccountTest:testValidateUserOp() (gas: 525509)
AccountTest:test__codesize() (gas: 65412)
AccountsTest:testDeploy() (gas: 1779383)
AccountsTest:test__codesize() (gas: 10223)
JointValidatorTest:testDeploy() (gas: 466944)
Expand All @@ -43,12 +43,12 @@ PaymentValidatorTest:testFailPaymentPlanInvalidAllowance() (gas: 185331)
PaymentValidatorTest:testInstall() (gas: 171005)
PermitValidatorTest:testAddressPermission(address) (runs: 256, μ: 23814, ~: 23814)
PermitValidatorTest:testBoolPermission(bool) (runs: 256, μ: 22209, ~: 22209)
PermitValidatorTest:testEnumPermission(uint256) (runs: 256, μ: 27311, ~: 27360)
PermitValidatorTest:testInstall() (gas: 207712)
PermitValidatorTest:testTransferPermission(address,uint256,uint256,uint256) (runs: 256, μ: 8652, ~: 3728)
PermitValidatorTest:testUintPermission(uint256,uint256,uint256) (runs: 256, μ: 6214, ~: 3262)
PermitValidatorTest:testEnumPermission(uint256) (runs: 256, μ: 27308, ~: 27360)
PermitValidatorTest:testInstall() (gas: 206920)
PermitValidatorTest:testTransferPermission(address,uint256,uint256,uint256) (runs: 256, μ: 8559, ~: 3728)
PermitValidatorTest:testUintPermission(uint256,uint256,uint256) (runs: 256, μ: 6744, ~: 3262)
PermitValidatorTest:testValuePermission(uint256,uint256) (runs: 256, μ: 20022, ~: 20023)
PermitValidatorTest:test__codesize() (gas: 48488)
PermitValidatorTest:test__codesize() (gas: 48102)
PointsTest:testCheck(uint256) (runs: 256, μ: 31230, ~: 31230)
PointsTest:testDeploy() (gas: 103095)
RecoveryValidatorTest:testDeploy() (gas: 1421598)
Expand Down
2 changes: 1 addition & 1 deletion lib/solady
Submodule solady updated 61 files
+1,010 −964 .gas-snapshot
+3 −0 .gitignore
+ audits/xuwinnie-solady-cbrt-proof.pdf
+5 −0 funding.json
+1 −1 package.json
+124 −2 src/utils/ECDSA.sol
+28 −6 src/utils/FixedPointMathLib.sol
+53 −6 src/utils/GasBurnerLib.sol
+47 −10 src/utils/LibBitmap.sol
+848 −16 src/utils/LibClone.sol
+83 −26 src/utils/Lifebuoy.sol
+2 −2 src/utils/MetadataReaderLib.sol
+29 −10 src/utils/MinHeapLib.sol
+6 −4 src/utils/P256.sol
+4 −3 src/utils/SSTORE2.sol
+1 −1 test/Base64.t.sol
+86 −0 test/Brutalizer.t.sol
+5 −18 test/DeploylessPredeployQueryer.t.sol
+24 −24 test/DynamicBufferLib.t.sol
+215 −0 test/ECDSA.t.sol
+11 −24 test/ERC1155.t.sol
+10 −10 test/ERC1271.t.sol
+4 −3 test/ERC1967Factory.t.sol
+4 −4 test/ERC2981.t.sol
+16 −8 test/ERC4337.t.sol
+1 −1 test/ERC4337Factory.t.sol
+4 −4 test/ERC6551.t.sol
+5 −5 test/ERC6909.t.sol
+18 −18 test/ERC721.t.sol
+32 −32 test/EnumerableSetLib.t.sol
+4 −0 test/FixedPointMathLib.t.sol
+70 −10 test/GasBurnerLib.t.sol
+56 −1 test/LibBitmap.t.sol
+621 −52 test/LibClone.t.sol
+8 −8 test/LibERC6551.t.sol
+9 −9 test/LibMap.t.sol
+4 −4 test/LibPRNG.t.sol
+1 −22 test/LibRLP.t.sol
+23 −23 test/LibSort.t.sol
+1 −1 test/LibString.t.sol
+6 −6 test/LibZip.t.sol
+88 −23 test/Lifebuoy.t.sol
+1 −1 test/MetadataReaderLib.t.sol
+86 −43 test/MinHeapLib.t.sol
+1 −1 test/Ownable.t.sol
+7 −7 test/OwnableRoles.t.sol
+7 −7 test/RedBlackTree.t.sol
+6 −32 test/SSTORE2.t.sol
+3 −3 test/SafeCastLib.t.sol
+3 −3 test/SafeTransferLib.t.sol
+8 −6 test/SignatureCheckerLib.t.sol
+36 −0 test/TestPlus.t.sol
+8 −8 test/UpgradeableBeacon.t.sol
+631 −34 test/utils/Brutalizer.sol
+467 −65 test/utils/TestPlus.sol
+10 −0 test/utils/mocks/MockERC1155.sol
+2 −2 test/utils/mocks/MockERC2981.sol
+1 −1 test/utils/mocks/MockERC721.sol
+41 −0 test/utils/mocks/MockLifebuoy.sol
+0 −13 test/utils/mocks/MockOwnable.sol
+0 −25 test/utils/mocks/MockOwnableRoles.sol
45 changes: 29 additions & 16 deletions src/paymasters/NEETH.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import "@solady/src/tokens/ERC20.sol";

/// @notice Simple wrapped ERC4337 implementation with paymaster and yield functions.
/// @author nani.eth (https://github.com/NaniDAO/accounts/blob/main/src/paymasters/NEETH.sol)
/// @custom:version 1.1.1
/// @custom:version 1.2.3
contract NEETH is ERC20 {
/// ========================= CONSTANTS ========================= ///

/// @dev The governing DAO address.
address internal constant DAO = 0xDa000000000000d2885F108500803dfBAaB2f2aA;

/// @dev The Uniswap V3 pool on Arbitrum for swapping between WETH & stETH.
address internal constant POOL = 0x35218a1cbaC5Bbc3E57fd9Bd38219D37571b3537;
address internal immutable POOL;

/// @dev The WETH contract for wrapping and unwrapping ETH on Arbitrum.
address internal constant WETH = 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1;
address internal immutable WETH;

/// @dev The yield token contract address (in V1, bridged wrapped stETH).
address internal constant YIELD = 0x5979D7b546E38E414F7E9822514be443A4800529;
address internal immutable YIELD;

/// @dev A canonical ERC4337 EntryPoint contract for NEETH alpha (0.6).
address internal constant EP06 = 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789;
Expand Down Expand Up @@ -86,23 +86,25 @@ contract NEETH is ERC20 {
/// @dev Requires that the caller is the DAO.
modifier onlyDAO() virtual {
assembly ("memory-safe") {
if iszero(eq(caller(), DAO)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), DAO)) { revert(codesize(), codesize()) }
}
_;
}

/// @dev Requires that the caller is the EntryPoint (0.6).
modifier onlyEntryPoint06() virtual {
address ep06 = EP06;
assembly ("memory-safe") {
if iszero(eq(caller(), EP06)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), ep06)) { revert(codesize(), codesize()) }
}
_;
}

/// @dev Requires that the caller is the EntryPoint (0.7).
modifier onlyEntryPoint07() virtual {
address ep07 = EP07;
assembly ("memory-safe") {
if iszero(eq(caller(), EP07)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), ep07)) { revert(codesize(), codesize()) }
}
_;
}
Expand All @@ -122,7 +124,9 @@ contract NEETH is ERC20 {
/// ======================== CONSTRUCTOR ======================== ///

/// @dev Constructs NEETH.
constructor() payable {}
constructor(address pool, address weth, address yield) payable {
(POOL, WETH, YIELD) = (pool, weth, yield);
}

/// ===================== DEPOSIT OPERATIONS ===================== ///

Expand Down Expand Up @@ -172,11 +176,12 @@ contract NEETH is ERC20 {

/// @dev Fallback `uniswapV3SwapCallback`.
fallback() external payable virtual {
address pool = POOL;
uint256 amount0Delta;
int256 amount1Delta;
bool zeroForOne;
assembly ("memory-safe") {
if iszero(eq(caller(), POOL)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), pool)) { revert(codesize(), 0x00) }
amount0Delta := calldataload(0x4)
amount1Delta := calldataload(0x24)
zeroForOne := byte(0, calldataload(0x84))
Expand All @@ -191,33 +196,36 @@ contract NEETH is ERC20 {

/// @dev Funds an `amount` of YIELD token (stETH) to pool caller for swap.
function _transferYieldToken(uint256 amount) internal virtual {
address yield = YIELD;
assembly ("memory-safe") {
mstore(0x14, caller()) // Store the `pool` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
pop(call(gas(), YIELD, 0, 0x10, 0x44, codesize(), 0x00))
pop(call(gas(), yield, 0, 0x10, 0x44, codesize(), 0x00))
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}

/// @dev Wraps an `amount` of ETH to WETH and funds pool caller for swap.
function _wrapETH(uint256 amount) internal virtual {
address weth = WETH;
assembly ("memory-safe") {
pop(call(gas(), WETH, amount, codesize(), 0x00, codesize(), 0x00))
pop(call(gas(), weth, amount, codesize(), 0x00, codesize(), 0x00))
mstore(0x14, caller()) // Store the `pool` argument.
mstore(0x34, amount) // Store the `amount` argument.
mstore(0x00, 0xa9059cbb000000000000000000000000) // `transfer(address,uint256)`.
pop(call(gas(), WETH, 0, 0x10, 0x44, codesize(), 0x00))
pop(call(gas(), weth, 0, 0x10, 0x44, codesize(), 0x00))
mstore(0x34, 0) // Restore the part of the free memory pointer that was overwritten.
}
}

/// @dev Unwraps an `amount` of ETH from WETH for return.
function _unwrapETH(uint256 amount) internal virtual {
address weth = WETH;
assembly ("memory-safe") {
mstore(0x00, 0x2e1a7d4d) // `withdraw(uint256)`.
mstore(0x20, amount) // Store the `amount` argument.
pop(call(gas(), WETH, 0, 0x1c, 0x24, codesize(), 0x00))
pop(call(gas(), weth, 0, 0x1c, 0x24, codesize(), 0x00))
}
}

Expand All @@ -234,8 +242,9 @@ contract NEETH is ERC20 {
/// @dev ETH receiver fallback.
/// Only canonical WETH can call.
receive() external payable virtual {
address weth = WETH;
assembly ("memory-safe") {
if iszero(eq(caller(), WETH)) { revert(codesize(), 0x00) }
if iszero(eq(caller(), weth)) { revert(codesize(), codesize()) }
}
}

Expand All @@ -247,7 +256,9 @@ contract NEETH is ERC20 {
bytes32, /*userOpHash*/
uint256 maxCost
) public payable virtual onlyEntryPoint06 returns (bytes memory, uint256) {
if (balanceOf(userOp.sender) >= maxCost) return (abi.encode(userOp.sender), 0x00);
if (balanceOf(userOp.sender) >= maxCost) {
return (abi.encode(userOp.sender), 0x00);
}
return ("", 0x01); // If insufficient NEETH, return fail code and empty context.
}

Expand All @@ -257,7 +268,9 @@ contract NEETH is ERC20 {
bytes32, /*userOpHash*/
uint256 maxCost
) public payable virtual onlyEntryPoint07 returns (bytes memory, uint256) {
if (balanceOf(userOp.sender) >= maxCost) return (abi.encode(userOp.sender), 0x00);
if (balanceOf(userOp.sender) >= maxCost) {
return (abi.encode(userOp.sender), 0x00);
}
return ("", 0x01); // If insufficient NEETH, return fail code and empty context.
}

Expand Down

0 comments on commit e8688d4

Please sign in to comment.