Commit 3b284850 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #8075 from ethereum-optimism/ctb/new-storage-setter

contracts-bedrock: update `StorageSetter`
parents fd4f61e7 b28023e5
This diff is collapsed.
...@@ -13,7 +13,7 @@ const StorageSetterStorageLayoutJSON = "{\"storage\":null,\"types\":{}}" ...@@ -13,7 +13,7 @@ const StorageSetterStorageLayoutJSON = "{\"storage\":null,\"types\":{}}"
var StorageSetterStorageLayout = new(solc.StorageLayout) var StorageSetterStorageLayout = new(solc.StorageLayout)
var StorageSetterDeployedBin = "0x608060405234801561001057600080fd5b506004361061007d5760003560e01c8063a6ed563e1161005b578063a6ed563e1461011c578063bd02d0f51461011c578063ca446dd914610138578063e2a4853a146100bf57600080fd5b806321f8a721146100825780634e91db08146100bf57806354fd4d50146100d3575b600080fd5b610095610090366004610156565b610146565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6100d16100cd36600461016f565b9055565b005b61010f6040518060400160405280600581526020017f312e302e3000000000000000000000000000000000000000000000000000000081525081565b6040516100b69190610191565b61012a610090366004610156565b6040519081526020016100b6565b6100d16100cd366004610204565b6000610150825490565b92915050565b60006020828403121561016857600080fd5b5035919050565b6000806040838503121561018257600080fd5b50508035926020909101359150565b600060208083528351808285015260005b818110156101be578581018301518582016040015282016101a2565b818111156101d0576000604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b6000806040838503121561021757600080fd5b82359150602083013573ffffffffffffffffffffffffffffffffffffffff8116811461024257600080fd5b80915050925092905056fea164736f6c634300080f000a" var StorageSetterDeployedBin = "0x608060405234801561001057600080fd5b50600436106100885760003560e01c8063a6ed563e1161005b578063a6ed563e1461013a578063bd02d0f51461013a578063ca446dd914610156578063e2a4853a146100df57600080fd5b80630528afe21461008d57806321f8a721146100a25780634e91db08146100df57806354fd4d50146100f1575b600080fd5b6100a061009b3660046101d7565b610164565b005b6100b56100b036600461024c565b6101c7565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6100a06100ed366004610265565b9055565b61012d6040518060400160405280600581526020017f312e312e3000000000000000000000000000000000000000000000000000000081525081565b6040516100d69190610287565b6101486100b036600461024c565b6040519081526020016100d6565b6100a06100ed3660046102fa565b8060005b818110156101c1576101af84848381811061018557610185610343565b905060400201600001358585848181106101a1576101a1610343565b905060400201602001359055565b806101b981610372565b915050610168565b50505050565b60006101d1825490565b92915050565b600080602083850312156101ea57600080fd5b823567ffffffffffffffff8082111561020257600080fd5b818501915085601f83011261021657600080fd5b81358181111561022557600080fd5b8660208260061b850101111561023a57600080fd5b60209290920196919550909350505050565b60006020828403121561025e57600080fd5b5035919050565b6000806040838503121561027857600080fd5b50508035926020909101359150565b600060208083528351808285015260005b818110156102b457858101830151858201604001528201610298565b818111156102c6576000604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b6000806040838503121561030d57600080fd5b82359150602083013573ffffffffffffffffffffffffffffffffffffffff8116811461033857600080fd5b809150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036103ca577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506001019056fea164736f6c634300080f000a"
func init() { func init() {
if err := json.Unmarshal([]byte(StorageSetterStorageLayoutJSON), StorageSetterStorageLayout); err != nil { if err := json.Unmarshal([]byte(StorageSetterStorageLayoutJSON), StorageSetterStorageLayout); err != nil {
......
...@@ -672,8 +672,8 @@ SequencerFeeVault_Test:test_withdraw_toL1_succeeds() (gas: 618343) ...@@ -672,8 +672,8 @@ SequencerFeeVault_Test:test_withdraw_toL1_succeeds() (gas: 618343)
SetPrevBaseFee_Test:test_setPrevBaseFee_succeeds() (gas: 11595) SetPrevBaseFee_Test:test_setPrevBaseFee_succeeds() (gas: 11595)
StandardBridge_Stateless_Test:test_isCorrectTokenPair_succeeds() (gas: 50149) StandardBridge_Stateless_Test:test_isCorrectTokenPair_succeeds() (gas: 50149)
StandardBridge_Stateless_Test:test_isOptimismMintableERC20_succeeds() (gas: 33142) StandardBridge_Stateless_Test:test_isOptimismMintableERC20_succeeds() (gas: 33142)
Storage_Roundtrip_Test:test_setGetAddress_succeeds(bytes32,address) (runs: 64, μ: 31532, ~: 31843) Storage_Roundtrip_Test:test_setGetAddress_succeeds(bytes32,address) (runs: 64, μ: 31221, ~: 31843)
Storage_Roundtrip_Test:test_setGetBytes32_succeeds(bytes32,bytes32) (runs: 64, μ: 31620, ~: 31620) Storage_Roundtrip_Test:test_setGetBytes32_succeeds(bytes32,bytes32) (runs: 64, μ: 31654, ~: 31654)
Storage_Roundtrip_Test:test_setGetUint_succeeds(bytes32,uint256) (runs: 64, μ: 30731, ~: 31664) Storage_Roundtrip_Test:test_setGetUint_succeeds(bytes32,uint256) (runs: 64, μ: 30731, ~: 31664)
SystemConfig_Initialize_Test:test_initialize_events_succeeds() (gas: 88186) SystemConfig_Initialize_Test:test_initialize_events_succeeds() (gas: 88186)
SystemConfig_Initialize_Test:test_initialize_startBlockNoop_reverts() (gas: 77216) SystemConfig_Initialize_Test:test_initialize_startBlockNoop_reverts() (gas: 77216)
......
...@@ -34,5 +34,5 @@ ...@@ -34,5 +34,5 @@
"src/universal/OptimismMintableERC20Factory.sol": "0x8d4cbf4cc30a0bb72925b5d2e0386b8f91559f00933a9c7cf3dcc118e34fe61b", "src/universal/OptimismMintableERC20Factory.sol": "0x8d4cbf4cc30a0bb72925b5d2e0386b8f91559f00933a9c7cf3dcc118e34fe61b",
"src/universal/OptimismMintableERC721.sol": "0x4c73bf8474fa7eb091796a4db7e57bc5f26d50a3d1cfcb78d5efa47ced5ced2b", "src/universal/OptimismMintableERC721.sol": "0x4c73bf8474fa7eb091796a4db7e57bc5f26d50a3d1cfcb78d5efa47ced5ced2b",
"src/universal/OptimismMintableERC721Factory.sol": "0x935fd97018b6ef10fa813d9d43ab7a77c80885f7a8d7feb430097645cb2abd2c", "src/universal/OptimismMintableERC721Factory.sol": "0x935fd97018b6ef10fa813d9d43ab7a77c80885f7a8d7feb430097645cb2abd2c",
"src/universal/StorageSetter.sol": "0x6372647d8a67d243bc2fb40d2c4bf5807022d94d52d9423cfed27a7d57918635" "src/universal/StorageSetter.sol": "0x394ec39ef24b44f54549deec6183cace8eea2e5313cde8d5a6e0411a481c5953"
} }
\ No newline at end of file
...@@ -9,9 +9,15 @@ import { Storage } from "src/libraries/Storage.sol"; ...@@ -9,9 +9,15 @@ import { Storage } from "src/libraries/Storage.sol";
/// WARNING: this contract is not safe to be called by untrusted parties. /// WARNING: this contract is not safe to be called by untrusted parties.
/// It is only meant as an intermediate step during upgrades. /// It is only meant as an intermediate step during upgrades.
contract StorageSetter is ISemver { contract StorageSetter is ISemver {
/// @notice Represents a storage slot key value pair.
struct Slot {
bytes32 key;
bytes32 value;
}
/// @notice Semantic version. /// @notice Semantic version.
/// @custom:semver 1.0.0 /// @custom:semver 1.1.0
string public constant version = "1.0.0"; string public constant version = "1.1.0";
/// @notice Stores a bytes32 `_value` at `_slot`. Any storage slots that /// @notice Stores a bytes32 `_value` at `_slot`. Any storage slots that
/// are packed should be set through this interface. /// are packed should be set through this interface.
...@@ -19,6 +25,14 @@ contract StorageSetter is ISemver { ...@@ -19,6 +25,14 @@ contract StorageSetter is ISemver {
Storage.setBytes32(_slot, _value); Storage.setBytes32(_slot, _value);
} }
/// @notice Stores a bytes32 value at each key in `_slots`.
function setBytes32(Slot[] calldata slots) public {
uint256 length = slots.length;
for (uint256 i; i < length; i++) {
Storage.setBytes32(slots[i].key, slots[i].value);
}
}
/// @notice Retrieves a bytes32 value from `_slot`. /// @notice Retrieves a bytes32 value from `_slot`.
function getBytes32(bytes32 _slot) external view returns (bytes32) { function getBytes32(bytes32 _slot) external view returns (bytes32) {
return Storage.getBytes32(_slot); return Storage.getBytes32(_slot);
......
...@@ -13,6 +13,11 @@ import { Test } from "forge-std/Test.sol"; ...@@ -13,6 +13,11 @@ import { Test } from "forge-std/Test.sol";
contract Storage_Roundtrip_Test is Test { contract Storage_Roundtrip_Test is Test {
StorageSetter setter; StorageSetter setter;
/// @notice A set of storage slots to pass to `setBytes32`.
StorageSetter.Slot[] slots;
/// @notice Used to deduplicate slots passed to `setBytes32`.
mapping(bytes32 => bool) keys;
function setUp() external { function setUp() external {
setter = new StorageSetter(); setter = new StorageSetter();
} }
...@@ -34,4 +39,21 @@ contract Storage_Roundtrip_Test is Test { ...@@ -34,4 +39,21 @@ contract Storage_Roundtrip_Test is Test {
assertEq(setter.getBytes32(slot), hash); assertEq(setter.getBytes32(slot), hash);
assertEq(hash, vm.load(address(setter), slot)); assertEq(hash, vm.load(address(setter), slot));
} }
/// @dev All keys must be unique in the input so deduplication is required.
function testFuzz_setGetBytes32Multi_succeeds(StorageSetter.Slot[] calldata _slots) external {
for (uint256 i; i < _slots.length; i++) {
if (keys[_slots[i].key]) {
continue;
}
slots.push(_slots[i]);
keys[_slots[i].key] = true;
}
setter.setBytes32(slots);
for (uint256 i; i < slots.length; i++) {
assertEq(setter.getBytes32(slots[i].key), slots[i].value);
assertEq(slots[i].value, vm.load(address(setter), slots[i].key));
}
}
} }
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