Commit 8bdb80d4 authored by Mark Tyneway's avatar Mark Tyneway

contracts-bedrock: add unsafe block signer

Added the key responsible for unsafe block distrubtion
to the `SystemConfig` contract. This allows for the `op-node`
to read this value and know what peers to accept unsafe blocks
from.
parent 63e3bec9
...@@ -16,14 +16,17 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -16,14 +16,17 @@ contract SystemConfig is OwnableUpgradeable, Semver {
/** /**
* @notice Enum representing different types of updates. * @notice Enum representing different types of updates.
* *
* @custom:value BATCHER Represents an update to the batcher hash. * @custom:value BATCHER Represents an update to the batcher hash.
* @custom:value GAS_CONFIG Represents an update to txn fee config on L2. * @custom:value GAS_CONFIG Represents an update to txn fee config on L2.
* @custom:value GAS_LIMIT Represents an update to gas limit on L2. * @custom:value GAS_LIMIT Represents an update to gas limit on L2.
* @custom:value UNSAFE_BLOCK_KEY Represents an update to the signer key for unsafe
* block distrubution.
*/ */
enum UpdateType { enum UpdateType {
BATCHER, BATCHER,
GAS_CONFIG, GAS_CONFIG,
GAS_LIMIT GAS_LIMIT,
UNSAFE_BLOCK_KEY
} }
/** /**
...@@ -54,6 +57,12 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -54,6 +57,12 @@ contract SystemConfig is OwnableUpgradeable, Semver {
*/ */
bytes32 public batcherHash; bytes32 public batcherHash;
/**
* @notice Address corresponding to the key that can propagate unsafe blocks
* across the p2p network.
*/
address public unsafeBlockSigner;
/** /**
* @notice L2 gas limit. * @notice L2 gas limit.
*/ */
...@@ -82,9 +91,10 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -82,9 +91,10 @@ contract SystemConfig is OwnableUpgradeable, Semver {
uint256 _overhead, uint256 _overhead,
uint256 _scalar, uint256 _scalar,
bytes32 _batcherHash, bytes32 _batcherHash,
uint64 _gasLimit uint64 _gasLimit,
address _unsafeBlockSigner
) Semver(1, 0, 0) { ) Semver(1, 0, 0) {
initialize(_owner, _overhead, _scalar, _batcherHash, _gasLimit); initialize(_owner, _overhead, _scalar, _batcherHash, _gasLimit, _unsafeBlockSigner);
} }
/** /**
...@@ -101,7 +111,8 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -101,7 +111,8 @@ contract SystemConfig is OwnableUpgradeable, Semver {
uint256 _overhead, uint256 _overhead,
uint256 _scalar, uint256 _scalar,
bytes32 _batcherHash, bytes32 _batcherHash,
uint64 _gasLimit uint64 _gasLimit,
address _unsafeBlockSigner
) public initializer { ) public initializer {
require(_gasLimit >= MINIMUM_GAS_LIMIT, "SystemConfig: gas limit too low"); require(_gasLimit >= MINIMUM_GAS_LIMIT, "SystemConfig: gas limit too low");
__Ownable_init(); __Ownable_init();
...@@ -110,6 +121,7 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -110,6 +121,7 @@ contract SystemConfig is OwnableUpgradeable, Semver {
scalar = _scalar; scalar = _scalar;
batcherHash = _batcherHash; batcherHash = _batcherHash;
gasLimit = _gasLimit; gasLimit = _gasLimit;
unsafeBlockSigner = _unsafeBlockSigner;
} }
/** /**
...@@ -139,6 +151,13 @@ contract SystemConfig is OwnableUpgradeable, Semver { ...@@ -139,6 +151,13 @@ contract SystemConfig is OwnableUpgradeable, Semver {
emit ConfigUpdate(VERSION, UpdateType.GAS_CONFIG, data); emit ConfigUpdate(VERSION, UpdateType.GAS_CONFIG, data);
} }
function setUnsafeBlockSigner(address _unsafeBlockSigner) external onlyOwner {
unsafeBlockSigner = _unsafeBlockSigner;
bytes memory data = abi.encode(_unsafeBlockSigner);
emit ConfigUpdate(VERSION, UpdateType.UNSAFE_BLOCK_KEY, data);
}
/** /**
* @notice Updates the L2 gas limit. * @notice Updates the L2 gas limit.
* *
......
...@@ -78,6 +78,7 @@ contract SystemDictator is OwnableUpgradeable { ...@@ -78,6 +78,7 @@ contract SystemDictator is OwnableUpgradeable {
uint256 scalar; uint256 scalar;
bytes32 batcherHash; bytes32 batcherHash;
uint64 gasLimit; uint64 gasLimit;
address unsafeBlockSigner;
} }
/** /**
...@@ -353,7 +354,8 @@ contract SystemDictator is OwnableUpgradeable { ...@@ -353,7 +354,8 @@ contract SystemDictator is OwnableUpgradeable {
config.systemConfigConfig.overhead, config.systemConfigConfig.overhead,
config.systemConfigConfig.scalar, config.systemConfigConfig.scalar,
config.systemConfigConfig.batcherHash, config.systemConfigConfig.batcherHash,
config.systemConfigConfig.gasLimit config.systemConfigConfig.gasLimit,
config.systemConfigConfig.unsafeBlockSigner
) )
) )
); );
......
...@@ -13,7 +13,8 @@ contract SystemConfig_Init is CommonTest { ...@@ -13,7 +13,8 @@ contract SystemConfig_Init is CommonTest {
_overhead: 2100, _overhead: 2100,
_scalar: 1000000, _scalar: 1000000,
_batcherHash: bytes32(hex"abcd"), _batcherHash: bytes32(hex"abcd"),
_gasLimit: 9_000_000 _gasLimit: 9_000_000,
_unsafeBlockSigner: address(1)
}); });
} }
} }
...@@ -29,7 +30,8 @@ contract SystemConfig_Initialize_TestFail is CommonTest { ...@@ -29,7 +30,8 @@ contract SystemConfig_Initialize_TestFail is CommonTest {
_overhead: 0, _overhead: 0,
_scalar: 0, _scalar: 0,
_batcherHash: bytes32(hex""), _batcherHash: bytes32(hex""),
_gasLimit: MINIMUM_GAS_LIMIT - 1 _gasLimit: MINIMUM_GAS_LIMIT - 1,
_unsafeBlockSigner: address(1)
}); });
} }
} }
...@@ -49,6 +51,11 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init { ...@@ -49,6 +51,11 @@ contract SystemConfig_Setters_TestFail is SystemConfig_Init {
vm.expectRevert("Ownable: caller is not the owner"); vm.expectRevert("Ownable: caller is not the owner");
sysConf.setGasLimit(0); sysConf.setGasLimit(0);
} }
function test_setUnsafeBlockSigner_notOwner_reverts() external {
vm.expectRevert("Ownable: caller is not the owner");
sysConf.setUnsafeBlockSigner(address(0x20));
}
} }
contract SystemConfig_Setters_Test is SystemConfig_Init { contract SystemConfig_Setters_Test is SystemConfig_Init {
...@@ -94,4 +101,17 @@ contract SystemConfig_Setters_Test is SystemConfig_Init { ...@@ -94,4 +101,17 @@ contract SystemConfig_Setters_Test is SystemConfig_Init {
sysConf.setGasLimit(newGasLimit); sysConf.setGasLimit(newGasLimit);
assertEq(sysConf.gasLimit(), newGasLimit); assertEq(sysConf.gasLimit(), newGasLimit);
} }
function testFuzz_setUnsafeBlockSigner_succeeds(address newUnsafeSigner) external {
vm.expectEmit(true, true, true, true);
emit ConfigUpdate(
0,
SystemConfig.UpdateType.UNSAFE_BLOCK_KEY,
abi.encode(newUnsafeSigner)
);
vm.prank(sysConf.owner());
sysConf.setUnsafeBlockSigner(newUnsafeSigner);
assertEq(sysConf.unsafeBlockSigner(), newUnsafeSigner);
}
} }
...@@ -17,6 +17,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -17,6 +17,7 @@ const deployFn: DeployFunction = async (hre) => {
hre.deployConfig.gasPriceOracleScalar, hre.deployConfig.gasPriceOracleScalar,
batcherHash, batcherHash,
hre.deployConfig.l2GenesisBlockGasLimit, hre.deployConfig.l2GenesisBlockGasLimit,
hre.deployConfig.p2pSequencerAddress,
], ],
postDeployAction: async (contract) => { postDeployAction: async (contract) => {
await assertContractVariable( await assertContractVariable(
...@@ -35,6 +36,11 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -35,6 +36,11 @@ const deployFn: DeployFunction = async (hre) => {
hre.deployConfig.gasPriceOracleScalar hre.deployConfig.gasPriceOracleScalar
) )
await assertContractVariable(contract, 'batcherHash', batcherHash) await assertContractVariable(contract, 'batcherHash', batcherHash)
await assertContractVariable(
contract,
'unsafeBlockSigner',
hre.deployConfig.p2pSequencerAddress
)
}, },
}) })
} }
......
...@@ -99,6 +99,7 @@ const deployFn: DeployFunction = async (hre) => { ...@@ -99,6 +99,7 @@ const deployFn: DeployFunction = async (hre) => {
32 32
), ),
gasLimit: hre.deployConfig.l2GenesisBlockGasLimit, gasLimit: hre.deployConfig.l2GenesisBlockGasLimit,
unsafeBlockSigner: hre.deployConfig.unsafeBlockSigner,
}, },
} }
......
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