Skip to content

Commit

Permalink
contract changes following the idea of ethereum-optimism/specs#122
Browse files Browse the repository at this point in the history
  • Loading branch information
blockchaindevsh committed Aug 23, 2024
1 parent ce49d0c commit 3ea2880
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
20 changes: 2 additions & 18 deletions packages/contracts-bedrock/src/L1/SystemConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ contract SystemConfig is OwnableUpgradeable, ISemver, IGasToken {
BATCHER,
GAS_CONFIG,
GAS_LIMIT,
UNSAFE_BLOCK_SIGNER,
BATCH_INBOX
UNSAFE_BLOCK_SIGNER
}

/// @notice Struct representing the addresses of L1 system contracts. These should be the
Expand Down Expand Up @@ -200,7 +199,7 @@ contract SystemConfig is OwnableUpgradeable, ISemver, IGasToken {
_setGasLimit(_gasLimit);

Storage.setAddress(UNSAFE_BLOCK_SIGNER_SLOT, _unsafeBlockSigner);
_setBatchInbox(_batchInbox);
Storage.setAddress(BATCH_INBOX_SLOT, _batchInbox);
Storage.setAddress(L1_CROSS_DOMAIN_MESSENGER_SLOT, _addresses.l1CrossDomainMessenger);
Storage.setAddress(L1_ERC_721_BRIDGE_SLOT, _addresses.l1ERC721Bridge);
Storage.setAddress(L1_STANDARD_BRIDGE_SLOT, _addresses.l1StandardBridge);
Expand Down Expand Up @@ -357,21 +356,6 @@ contract SystemConfig is OwnableUpgradeable, ISemver, IGasToken {
emit ConfigUpdate(VERSION, UpdateType.BATCHER, data);
}

/// @notice Updates the batch inbox address. Can only be called by the owner.
/// @param _batchInbox New batch inbox address.
function setBatchInbox(address _batchInbox) external onlyOwner {
_setBatchInbox(_batchInbox);
}

/// @notice Updates the batch inbox address.
/// @param _batchInbox New batch inbox address.
function _setBatchInbox(address _batchInbox) internal {
Storage.setAddress(BATCH_INBOX_SLOT, _batchInbox);

bytes memory data = abi.encode(_batchInbox);
emit ConfigUpdate(VERSION, UpdateType.BATCH_INBOX, data);
}

/// @notice Updates gas config. Can only be called by the owner.
/// Deprecated in favor of setGasConfigEcotone since the Ecotone upgrade.
/// @param _overhead New overhead value.
Expand Down
14 changes: 14 additions & 0 deletions packages/contracts-bedrock/src/L1/SystemConfigInterop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,18 @@ contract SystemConfigInterop is SystemConfig {
ConfigType.REMOVE_DEPENDENCY, StaticConfig.encodeRemoveDependency(_chainId)
);
}

/// @notice Updates the batch inbox address. Can only be called by the owner.
/// @param _batchInbox New batch inbox address.
function setBatchInbox(address _batchInbox) external onlyOwner {
if (_batchInbox != batchInbox()) {
Storage.setAddress(BATCH_INBOX_SLOT, _batchInbox);
OptimismPortal(payable(optimismPortal())).setConfig(
ConfigType.SET_BATCH_INBOX,
StaticConfig.encodeSetBatchInbox({
_batchInbox: _batchInbox,
})
);
}
}
}
4 changes: 0 additions & 4 deletions packages/contracts-bedrock/src/L2/L1Block.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ contract L1Block is ISemver, IGasToken {
/// @notice The versioned hash to authenticate the batcher by.
bytes32 public batcherHash;

/// @notice The canonical batch inbox.
bytes32 public batchInbox;

/// @notice The overhead value applied to the L1 portion of the transaction fee.
/// @custom:legacy
uint256 public l1FeeOverhead;
Expand Down Expand Up @@ -152,7 +149,6 @@ contract L1Block is ISemver, IGasToken {
sstore(blobBaseFee.slot, calldataload(68)) // uint256
sstore(hash.slot, calldataload(100)) // bytes32
sstore(batcherHash.slot, calldataload(132)) // bytes32
sstore(batchInbox.slot, calldataload(164)) // bytes32
}
}

Expand Down
15 changes: 14 additions & 1 deletion packages/contracts-bedrock/src/L2/L1BlockInterop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import "src/libraries/L1BlockErrors.sol";
/// @custom:value SET_GAS_PAYING_TOKEN Represents the config type for setting the gas paying token.
/// @custom:value ADD_DEPENDENCY Represents the config type for adding a chain to the interop dependency set.
/// @custom:value REMOVE_DEPENDENCY Represents the config type for removing a chain from the interop dependency set.
/// @custom:value SET_BATCH_INBOX Represents the config type for setting the batch inbox.
enum ConfigType {
SET_GAS_PAYING_TOKEN,
ADD_DEPENDENCY,
REMOVE_DEPENDENCY
REMOVE_DEPENDENCY,
SET_BATCH_INBOX
}

/// @custom:proxied
Expand All @@ -33,6 +35,9 @@ contract L1BlockInterop is L1Block {
/// @notice The interop dependency set, containing the chain IDs in it.
EnumerableSet.UintSet dependencySet;

/// @notice The batch inbox address.
address batchInbox;

/// @custom:semver +interop
function version() public pure override returns (string memory) {
return string.concat(super.version(), "+interop");
Expand Down Expand Up @@ -65,6 +70,8 @@ contract L1BlockInterop is L1Block {
_addDependency(_value);
} else if (_type == ConfigType.REMOVE_DEPENDENCY) {
_removeDependency(_value);
} else if (_type == ConfigType.SET_BATCH_INBOX) {
_setBatchInbox(_value);
}
}

Expand Down Expand Up @@ -101,4 +108,10 @@ contract L1BlockInterop is L1Block {

emit DependencyRemoved(chainId);
}

/// @notice Internal method to set the batch inbox address.
/// @param _value The encoded value with which to set the batch inbox address.
function _setBatchInbox(bytes calldata _value) internal {
batchInbox = StaticConfig.decodeSetBatchInbox(_value);
}
}
14 changes: 14 additions & 0 deletions packages/contracts-bedrock/src/libraries/StaticConfig.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ library StaticConfig {
function decodeRemoveDependency(bytes memory _data) internal pure returns (uint256) {
return abi.decode(_data, (uint256));
}

/// @notice Encodes the static configuration data for setting a batch inbox.
/// @param _batchInbox Address of the batch inbox.
/// @return Encoded static configuration data.
function encodeSetBatchInbox(address _batchInbox) internal pure returns (bytes memory) {
return abi.encode(_batchInbox);
}

/// @notice Decodes the static configuration data for setting a batch inbox.
/// @param _data Encoded static configuration data.
/// @return Decoded Address of the batch inbox.
function decodeSetBatchInbox(bytes memory _data) internal pure returns (address) {
return abi.decode(_data, (address));
}
}

0 comments on commit 3ea2880

Please sign in to comment.