Commit bc7be453 authored by Mark Tyneway's avatar Mark Tyneway Committed by Matthew Slipper

contracts-bedrock: deterministic storage

Makes the storage slot deterministic for the unsafe
block signer. This is useful because the `op-node` uses
a storage proof to fetch the value, so the `op-node` can
compute the storage slot value locally. This decouples
the way that `solc` lays out storage from the network policy,
making bugs less likely to happen when changing the contracts.
parent f7f6d76f
This diff is collapsed.
This diff is collapsed.
...@@ -379,8 +379,8 @@ SequencerFeeVault_Test:test_minWithdrawalAmount_succeeds() (gas: 5420) ...@@ -379,8 +379,8 @@ SequencerFeeVault_Test:test_minWithdrawalAmount_succeeds() (gas: 5420)
SequencerFeeVault_Test:test_receive_succeeds() (gas: 17336) SequencerFeeVault_Test:test_receive_succeeds() (gas: 17336)
SequencerFeeVault_Test:test_withdraw_notEnough_reverts() (gas: 9309) SequencerFeeVault_Test:test_withdraw_notEnough_reverts() (gas: 9309)
SequencerFeeVault_Test:test_withdraw_succeeds() (gas: 159816) SequencerFeeVault_Test:test_withdraw_succeeds() (gas: 159816)
SystemConfig_Initialize_TestFail:test_initialize_lowGasLimit_reverts() (gas: 61952) SystemConfig_Initialize_TestFail:test_initialize_lowGasLimit_reverts() (gas: 61966)
SystemConfig_Setters_TestFail:test_setBatcherHash_notOwner_reverts() (gas: 10523) SystemConfig_Setters_TestFail:test_setBatcherHash_notOwner_reverts() (gas: 10545)
SystemConfig_Setters_TestFail:test_setGasConfig_notOwner_reverts() (gas: 10510) SystemConfig_Setters_TestFail:test_setGasConfig_notOwner_reverts() (gas: 10532)
SystemConfig_Setters_TestFail:test_setGasLimit_notOwner_reverts() (gas: 10614) SystemConfig_Setters_TestFail:test_setGasLimit_notOwner_reverts() (gas: 10636)
SystemConfig_Setters_TestFail:test_setUnsafeBlockSigner_notOwner_reverts() (gas: 10638) SystemConfig_Setters_TestFail:test_setUnsafeBlockSigner_notOwner_reverts() (gas: 10638)
...@@ -34,6 +34,13 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -34,6 +34,13 @@ contract SystemConfig is OwnableUpgradeable, Semver {
*/ */
uint256 public constant VERSION = 0; uint256 public constant VERSION = 0;
/**
* @notice Storage slot that the unsafe block signer is stored at. Storing it at this
* deterministic storage slot allows for decoupling the storage layout from the way
* that `solc` lays out storage. The `op-node` uses a storage proof to fetch this value.
*/
bytes32 public constant UNSAFE_BLOCK_SIGNER_SLOT = keccak256("systemconfig.unsafeblocksigner");
/** /**
* @notice Minimum gas limit. This should not be lower than the maximum deposit gas resource * @notice Minimum gas limit. This should not be lower than the maximum deposit gas resource
* limit in the ResourceMetering contract used by OptimismPortal, to ensure the L2 * limit in the ResourceMetering contract used by OptimismPortal, to ensure the L2
...@@ -51,13 +58,6 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -51,13 +58,6 @@ contract SystemConfig is OwnableUpgradeable, Semver {
*/ */
uint256 public scalar; uint256 public scalar;
/**
* @notice Address corresponding to the key that can propagate unsafe blocks
* across the p2p network. This value should not be tightly packed
* into a storage slot with another value to make state proofs more simple.
*/
address public unsafeBlockSigner;
/** /**
* @notice Identifier for the batcher. For version 1 of this configuration, this is represented * @notice Identifier for the batcher. For version 1 of this configuration, this is represented
* as an address left-padded with zeros to 32 bytes. * as an address left-padded with zeros to 32 bytes.
...@@ -122,7 +122,21 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -122,7 +122,21 @@ contract SystemConfig is OwnableUpgradeable, Semver {
scalar = _scalar; scalar = _scalar;
batcherHash = _batcherHash; batcherHash = _batcherHash;
gasLimit = _gasLimit; gasLimit = _gasLimit;
unsafeBlockSigner = _unsafeBlockSigner; _setUnsafeBlockSigner(_unsafeBlockSigner);
}
/**
* @notice High level getter for the unsafe block signer address.
* Unsafe blocks can be propagated across the p2p network
* if they are signed by the key corresponding to this address.
*/
function unsafeBlockSigner() public view returns (address) {
address addr;
bytes32 slot = UNSAFE_BLOCK_SIGNER_SLOT;
assembly {
addr := sload(slot)
}
return addr;
} }
/** /**
...@@ -153,12 +167,26 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -153,12 +167,26 @@ contract SystemConfig is OwnableUpgradeable, Semver {
} }
function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner { function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner {
unsafeBlockSigner = _unsafeBlockSigner; _setUnsafeBlockSigner(_unsafeBlockSigner);
bytes memory data = abi.encode(_unsafeBlockSigner); bytes memory data = abi.encode(_unsafeBlockSigner);
emit ConfigUpdate(VERSION, UpdateType.UNSAFE_BLOCK_SIGNER, data); emit ConfigUpdate(VERSION, UpdateType.UNSAFE_BLOCK_SIGNER, data);
} }
/**
* @notice Low level setter for the unsafe block signer address.
* This function exists to deduplicate code around storing
* the unsafeBlockSigner address in storage.
*
* @param _unsafeBlockSigner New unsafeBlockSigner value
*/
function _setUnsafeBlockSigner(address _unsafeBlockSigner) internal {
bytes32 slot = UNSAFE_BLOCK_SIGNER_SLOT;
assembly {
sstore(slot, _unsafeBlockSigner)
}
}
/** /**
* @notice Updates the L2 gas limit. * @notice Updates the L2 gas limit.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment