Skip to content

Commit

Permalink
Use transient storage slot to pass the request
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Feb 18, 2025
1 parent d325f00 commit 7b45729
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ auto_detect_solc = false
optimizer = true
optimizer_runs = 1_000
gas_limit = 100_000_000 # ETH is 30M, but we use a higher value.
skip = ["*/*Transient*", "*/ext/ithaca/*", "*/ext/zksync/*"]
skip = ["*/*7702*", "*/*Transient*", "*/ext/ithaca/*", "*/ext/zksync/*"]
fs_permissions = [{ access = "read", path = "./test/data"}]
remappings = [
"forge-std=test/utils/forge-std/"
]

[profile.pre_global_structs]
skip = ["*/g/*", "*/*Transient*", "*/ext/ithaca/*", "*/ext/zksync/*"]
skip = ["*/g/*", "*/*7702*", "*/*Transient*", "*/ext/ithaca/*", "*/ext/zksync/*"]

[profile.post_cancun]
evm_version = "cancun"
Expand Down
2 changes: 0 additions & 2 deletions src/Milady.sol
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;

import "./accounts/EIP7702Proxy.sol";
import "./accounts/ERC1271.sol";
import "./accounts/ERC4337.sol";
import "./accounts/ERC4337Factory.sol";
import "./accounts/ERC6551.sol";
import "./accounts/ERC6551Proxy.sol";
import "./accounts/ERC7821.sol";
import "./accounts/LibEIP7702.sol";
import "./accounts/LibERC6551.sol";
import "./accounts/LibERC7579.sol";
import "./accounts/Receiver.sol";
Expand Down
18 changes: 10 additions & 8 deletions src/accounts/EIP7702Proxy.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.24;

/// @notice Relay proxy for EIP7702 delegations.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/accounts/EIP7702Proxy.sol)
Expand Down Expand Up @@ -33,10 +33,10 @@ contract EIP7702Proxy {
bytes32 internal constant _ERC1967_ADMIN_SLOT =
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;

/// @dev The prefix for the ERC-1967 storage slot value if it should
/// be initialized with the latest implementation.
/// `uint32(bytes4(keccak256("eip7702.proxy.delegation.initialization")))`
uint32 internal constant _EIP7702_PROXY_DELEGATION_INITIALIZATION_PREFIX = 0x17723f10;
/// @dev The transient storage slot for requesting the proxy to initialize the implementation.
/// `uint256(keccak256("eip7702.proxy.delegation.initialization.request")) - 1`.
bytes32 internal constant _EIP7702_PROXY_DELEGATION_INITIALIZATION_REQUEST_SLOT =
0x94e11c6e41e7fb92cb8bb65e13fdfbd4eba8b831292a1a220f7915c78c7c078f;

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* CONSTRUCTOR */
Expand Down Expand Up @@ -124,10 +124,12 @@ contract EIP7702Proxy {
// to signal that we should replace it with the actual implementation.
// This also gives the flexibility on whether to let the proxy auto-upgrade,
// or let the authority manually upgrade.
let implSlot := _ERC1967_IMPLEMENTATION_SLOT
if eq(_EIP7702_PROXY_DELEGATION_INITIALIZATION_PREFIX, shr(224, sload(implSlot))) {
// A non-zero value in transient storage denotes a initialization request.
if tload(_EIP7702_PROXY_DELEGATION_INITIALIZATION_REQUEST_SLOT) {
let implSlot := _ERC1967_IMPLEMENTATION_SLOT
// The `implementation` is still at `calldatasize()` in memory.
sstore(implSlot, or(shl(160, shr(160, impl)), mload(calldatasize())))
sstore(implSlot, or(shl(160, shr(160, sload(implSlot))), mload(calldatasize())))
tstore(_EIP7702_PROXY_DELEGATION_INITIALIZATION_REQUEST_SLOT, 0) // Clear.
}
returndatacopy(0x00, 0x00, returndatasize())
return(0x00, returndatasize())
Expand Down
18 changes: 7 additions & 11 deletions src/accounts/LibEIP7702.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
pragma solidity ^0.8.24;

/// @notice Library for EIP7702 operations.
/// @author Solady (https://github.com/vectorized/solady/blob/main/src/accounts/LibEIP7702.sol)
Expand All @@ -26,10 +26,10 @@ library LibEIP7702 {
bytes32 internal constant ERC1967_IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;

/// @dev The prefix for the ERC-1967 storage slot value if it should
/// be initialized with the latest implementation.
/// `uint32(bytes4(keccak256("eip7702.proxy.delegation.initialization")))`
uint32 internal constant EIP7702_PROXY_DELEGATION_INITIALIZATION_PREFIX = 0x17723f10;
/// @dev The transient storage slot for requesting the proxy to initialize the implementation.
/// `uint256(keccak256("eip7702.proxy.delegation.initialization.request")) - 1`.
bytes32 internal constant _EIP7702_PROXY_DELEGATION_INITIALIZATION_REQUEST_SLOT =
0x94e11c6e41e7fb92cb8bb65e13fdfbd4eba8b831292a1a220f7915c78c7c078f;

/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* AUTHORITY OPERATIONS */
Expand Down Expand Up @@ -138,12 +138,8 @@ library LibEIP7702 {
function requestProxyDelegationInitialization() internal {
/// @solidity memory-safe-assembly
assembly {
let s := ERC1967_IMPLEMENTATION_SLOT
let v := sload(s)
if iszero(shl(96, v)) {
mstore(0x20, v)
mstore(0x04, EIP7702_PROXY_DELEGATION_INITIALIZATION_PREFIX)
sstore(s, mload(0x20))
if iszero(shl(96, sload(ERC1967_IMPLEMENTATION_SLOT))) {
tstore(_EIP7702_PROXY_DELEGATION_INITIALIZATION_REQUEST_SLOT, address())
}
}
}
Expand Down

0 comments on commit 7b45729

Please sign in to comment.