Skip to content

Commit

Permalink
drop IMMUTABLE_IMPLS_SLOT in favor of clearer code
Browse files Browse the repository at this point in the history
  • Loading branch information
smarx committed Nov 6, 2020
1 parent 80fbd28 commit 35fff28
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions contracts/zero-ex/contracts/src/ZeroEx.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import "./storage/LibProxyStorage.sol";
/// @dev An extensible proxy contract that serves as a universal entry point for
/// interacting with the 0x protocol.
contract ZeroEx {
uint256 immutable private IMMUTABLE_IMPLS_SLOT;

/// @dev Construct this contract and register the `BootstrapFeature` feature.
/// After constructing this contract, `bootstrap()` should be called
/// by `bootstrap()` to seed the initial feature set.
Expand All @@ -35,25 +33,18 @@ contract ZeroEx {
// Temporarily create and register the bootstrap feature.
// It will deregister itself after `bootstrap()` has been called.
BootstrapFeature bootstrap = new BootstrapFeature(bootstrapper);
mapping(bytes4 => address) storage impls =
LibProxyStorage.getStorage().impls;
impls[bootstrap.bootstrap.selector] = address(bootstrap);

// Store the slot for impls so it's accessible as a constant in Yul.
// Yul can't directly access immutables, so we have to go through a
// local.
uint256 implsSlot;
assembly { implsSlot := impls_slot }
IMMUTABLE_IMPLS_SLOT = implsSlot;
LibProxyStorage.getStorage().impls[bootstrap.bootstrap.selector] =
address(bootstrap);
}


// solhint-disable state-visibility

/// @dev Forwards calls to the appropriate implementation contract.
fallback() external payable {
// Yul can't directly access immutables.
uint256 implsSlot = IMMUTABLE_IMPLS_SLOT;
// This is used in assembly below as impls_slot.
mapping(bytes4 => address) storage impls =
LibProxyStorage.getStorage().impls;

assembly {
let cdlen := calldatasize()
Expand All @@ -69,7 +60,7 @@ contract ZeroEx {

// Slot for impls[selector] is keccak256(selector . impls_slot).
mstore(0, selector)
mstore(0x20, implsSlot)
mstore(0x20, impls_slot)
let slot := keccak256(0, 0x40)

let delegate := sload(slot)
Expand Down

0 comments on commit 35fff28

Please sign in to comment.