Commit eddb8113 authored by Mark Tyneway's avatar Mark Tyneway Committed by GitHub

Merge pull request #8435 from ethereum-optimism/ctb/set-bool

contracts-bedrock: add bool getter/setter to `Storage.sol`
parents e4de5602 890a44a5
This diff is collapsed.
......@@ -13,7 +13,7 @@ const StorageSetterStorageLayoutJSON = "{\"storage\":null,\"types\":{}}"
var StorageSetterStorageLayout = new(solc.StorageLayout)
var StorageSetterDeployedBin = "0x608060405234801561001057600080fd5b50600436106100885760003560e01c8063a6ed563e1161005b578063a6ed563e1461013a578063bd02d0f51461013a578063ca446dd914610156578063e2a4853a146100df57600080fd5b80630528afe21461008d57806321f8a721146100a25780634e91db08146100df57806354fd4d50146100f1575b600080fd5b6100a061009b3660046101d7565b610164565b005b6100b56100b036600461024c565b6101c7565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6100a06100ed366004610265565b9055565b61012d6040518060400160405280600581526020017f312e312e3000000000000000000000000000000000000000000000000000000081525081565b6040516100d69190610287565b6101486100b036600461024c565b6040519081526020016100d6565b6100a06100ed3660046102fa565b8060005b818110156101c1576101af84848381811061018557610185610343565b905060400201600001358585848181106101a1576101a1610343565b905060400201602001359055565b806101b981610372565b915050610168565b50505050565b60006101d1825490565b92915050565b600080602083850312156101ea57600080fd5b823567ffffffffffffffff8082111561020257600080fd5b818501915085601f83011261021657600080fd5b81358181111561022557600080fd5b8660208260061b850101111561023a57600080fd5b60209290920196919550909350505050565b60006020828403121561025e57600080fd5b5035919050565b6000806040838503121561027857600080fd5b50508035926020909101359150565b600060208083528351808285015260005b818110156102b457858101830151858201604001528201610298565b818111156102c6576000604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b6000806040838503121561030d57600080fd5b82359150602083013573ffffffffffffffffffffffffffffffffffffffff8116811461033857600080fd5b809150509250929050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff82036103ca577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506001019056fea164736f6c634300080f000a"
var StorageSetterDeployedBin = "0x608060405234801561001057600080fd5b50600436106100be5760003560e01c8063a6ed563e11610076578063bd02d0f51161005b578063bd02d0f51461018e578063ca446dd9146101b8578063e2a4853a1461011557600080fd5b8063a6ed563e1461018e578063abfdcced146101aa57600080fd5b80634e91db08116100a75780634e91db081461011557806354fd4d50146101275780637ae1cfca1461017057600080fd5b80630528afe2146100c357806321f8a721146100d8575b600080fd5b6100d66100d1366004610239565b6101c6565b005b6100eb6100e63660046102ae565b610229565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6100d66101233660046102c7565b9055565b6101636040518060400160405280600581526020017f312e322e3000000000000000000000000000000000000000000000000000000081525081565b60405161010c91906102e9565b61017e6100e63660046102ae565b604051901515815260200161010c565b61019c6100e63660046102ae565b60405190815260200161010c565b6100d661012336600461035c565b6100d6610123366004610391565b8060005b81811015610223576102118484838181106101e7576101e76103cf565b90506040020160000135858584818110610203576102036103cf565b905060400201602001359055565b8061021b816103fe565b9150506101ca565b50505050565b6000610233825490565b92915050565b6000806020838503121561024c57600080fd5b823567ffffffffffffffff8082111561026457600080fd5b818501915085601f83011261027857600080fd5b81358181111561028757600080fd5b8660208260061b850101111561029c57600080fd5b60209290920196919550909350505050565b6000602082840312156102c057600080fd5b5035919050565b600080604083850312156102da57600080fd5b50508035926020909101359150565b600060208083528351808285015260005b81811015610316578581018301518582016040015282016102fa565b81811115610328576000604083870101525b50601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe016929092016040019392505050565b6000806040838503121561036f57600080fd5b823591506020830135801515811461038657600080fd5b809150509250929050565b600080604083850312156103a457600080fd5b82359150602083013573ffffffffffffffffffffffffffffffffffffffff8116811461038657600080fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b60007fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8203610456577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b506001019056fea164736f6c634300080f000a"
func init() {
......
......@@ -148,7 +148,7 @@
"sourceCodeHash": "0x89cab3bfb4a6a6146336585216c78f20733219ac6973e7fc1cb49c43c060662d"
},
"src/universal/StorageSetter.sol": {
"initCodeHash": "0xb579792cbef7a862d60190712b3b5bc6b5ec8e2d0d4cc75a4ca9980490e3c238",
"sourceCodeHash": "0xc5d4a62bcb4dfe1844c72d40b21375769004e9dc76f6f293ee1ecb35abe58a92"
"initCodeHash": "0xb656d2aa6aff3e6435e747a0c23236d1b66f1f5c0b45e4b1a10d290a90223c5a",
"sourceCodeHash": "0xebfc968e6b78d7ea355547d427300739f14d000a11ff35f29d9ded3ddb7882da"
}
}
\ No newline at end of file
......@@ -11,13 +11,32 @@
"outputs": [
{
"internalType": "address",
"name": "",
"name": "addr_",
"type": "address"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_slot",
"type": "bytes32"
}
],
"name": "getBool",
"outputs": [
{
"internalType": "bool",
"name": "value_",
"type": "bool"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
......@@ -30,7 +49,7 @@
"outputs": [
{
"internalType": "bytes32",
"name": "",
"name": "value_",
"type": "bytes32"
}
],
......@@ -49,7 +68,7 @@
"outputs": [
{
"internalType": "uint256",
"name": "",
"name": "value_",
"type": "uint256"
}
],
......@@ -74,6 +93,24 @@
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_slot",
"type": "bytes32"
},
{
"internalType": "bool",
"name": "_value",
"type": "bool"
}
],
"name": "setBool",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
......
......@@ -58,7 +58,7 @@ library Storage {
/// @notice Stores a bytes32 value in an arbitrary storage slot, `_slot`.
/// @param _slot The storage slot to store the address in.
/// @param _value The protocol version to store
/// @param _value The bytes32 value to store.
/// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
/// in arbitrary storage slots.
function setBytes32(bytes32 _slot, bytes32 _value) internal {
......@@ -66,4 +66,23 @@ library Storage {
sstore(_slot, _value)
}
}
/// @notice Stores a bool value in an arbitrary storage slot, `_slot`.
/// @param _slot The storage slot to store the bool in.
/// @param _value The bool value to store
/// @dev WARNING! This function must be used cautiously, as it allows for overwriting values
/// in arbitrary storage slots.
function setBool(bytes32 _slot, bool _value) internal {
assembly {
sstore(_slot, _value)
}
}
/// @notice Returns a bool stored in an arbitrary storage slot.
/// @param _slot The storage slot to retrieve the bool from.
function getBool(bytes32 _slot) internal view returns (bool value_) {
assembly {
value_ := sload(_slot)
}
}
}
......@@ -16,8 +16,8 @@ contract StorageSetter is ISemver {
}
/// @notice Semantic version.
/// @custom:semver 1.1.0
string public constant version = "1.1.0";
/// @custom:semver 1.2.0
string public constant version = "1.2.0";
/// @notice Stores a bytes32 `_value` at `_slot`. Any storage slots that
/// are packed should be set through this interface.
......@@ -34,8 +34,8 @@ contract StorageSetter is ISemver {
}
/// @notice Retrieves a bytes32 value from `_slot`.
function getBytes32(bytes32 _slot) external view returns (bytes32) {
return Storage.getBytes32(_slot);
function getBytes32(bytes32 _slot) external view returns (bytes32 value_) {
value_ = Storage.getBytes32(_slot);
}
/// @notice Stores a uint256 `_value` at `_slot`.
......@@ -44,8 +44,8 @@ contract StorageSetter is ISemver {
}
/// @notice Retrieves a uint256 value from `_slot`.
function getUint(bytes32 _slot) external view returns (uint256) {
return Storage.getUint(_slot);
function getUint(bytes32 _slot) external view returns (uint256 value_) {
value_ = Storage.getUint(_slot);
}
/// @notice Stores an address `_value` at `_slot`.
......@@ -54,7 +54,17 @@ contract StorageSetter is ISemver {
}
/// @notice Retrieves an address value from `_slot`.
function getAddress(bytes32 _slot) external view returns (address) {
return Storage.getAddress(_slot);
function getAddress(bytes32 _slot) external view returns (address addr_) {
addr_ = Storage.getAddress(_slot);
}
/// @notice Stores a bool `_value` at `_slot`.
function setBool(bytes32 _slot, bool _value) public {
Storage.setBool(_slot, _value);
}
/// @notice Retrieves a bool value from `_slot`.
function getBool(bytes32 _slot) external view returns (bool value_) {
value_ = Storage.getBool(_slot);
}
}
......@@ -40,6 +40,12 @@ contract Storage_Roundtrip_Test is Test {
assertEq(hash, vm.load(address(setter), slot));
}
function test_setGetBool_succeeds(bytes32 slot, bool value) external {
setter.setBool(slot, value);
assertEq(setter.getBool(slot), value);
assertEq(value, vm.load(address(setter), slot) == bytes32(uint256(1)));
}
/// @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++) {
......
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