Skip to content

Commit

Permalink
Merge pull request #121 from oasysgames/feat/supporting-tools-fe
Browse files Browse the repository at this point in the history
support building from tools-fe
  • Loading branch information
tak1827 authored Mar 21, 2024
2 parents f975e8f + 3c54fed commit 289f773
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ contract Build is Script {
l2OutputOracleProposer: deployCfg.l2OutputOracleProposer,
l2OutputOracleChallenger: deployCfg.l2OutputOracleChallenger,
batchSenderAddress: deployCfg.batchSenderAddress,
p2pSequencerAddress: deployCfg.p2pSequencerAddress,
l2BlockTime: deployCfg.l2BlockTime,
l2GasLimit: uint64(deployCfg.l2GenesisBlockGasLimit),
l2OutputOracleSubmissionInterval: deployCfg.l2OutputOracleSubmissionInterval,
Expand Down
42 changes: 29 additions & 13 deletions packages/contracts-bedrock/src/oasys/L1/build/L1BuildAgent.sol
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ contract L1BuildAgent is IL1BuildAgent, ISemver {
/// @custom:semver 2.0.0
string public constant version = "2.0.0";

/// @notice The map of chainId => SystemConfig contract address
/// The SystemConfig holds the addresses of the other contracts, So agent don't manage it
mapping(uint256 => address) public chainSystemConfig;
/// @notice The map of chainId => builder
mapping(uint256 => address) public builders;

/// @notice The map of chainId => BuiltAddressList
mapping(uint256 => BuiltAddressList) public builtLists;

/// @notice List of chainIds that have been deployed, Return all chainIds at once
/// The size of the array isn't a concern; the limitation lies in the gas cost and comuputaion time.
Expand Down Expand Up @@ -119,6 +121,10 @@ contract L1BuildAgent is IL1BuildAgent, ISemver {
// Mark this builder as built.
L1_BUILD_DEPOSIT.build(msg.sender);

// register the builder
// Mark this chainId as built
builders[_chainId] = msg.sender;

// temporarily set the admin to this contract
// transfer ownership to the final system owner at the end of building
address admin = address(this);
Expand All @@ -141,7 +147,22 @@ contract L1BuildAgent is IL1BuildAgent, ISemver {
// L2 tx bathch is sent to this address
address batchInbox = computeInboxAddress(_chainId);

emit Deployed(_cfg.finalSystemOwner, address(proxyAdmin), proxys, impls, batchInbox, addressManager);
emit Deployed(_chainId, _cfg.finalSystemOwner, address(proxyAdmin), proxys, impls, batchInbox, addressManager);

// register built addresses to the builtLists
builtLists[_chainId].proxyAdmin = address(proxyAdmin);
builtLists[_chainId].systemConfig = proxys[2];
builtLists[_chainId].l1StandardBridge = proxys[4];
builtLists[_chainId].l1ERC721Bridge = proxys[5];
builtLists[_chainId].l1CrossDomainMessenger = proxys[3];
builtLists[_chainId].oasysL2OutputOracle = proxys[1];
builtLists[_chainId].oasysPortal = proxys[0];
builtLists[_chainId].protocolVersions = proxys[6];
builtLists[_chainId].batchInbox = batchInbox;
builtLists[_chainId].addressManager = addressManager;

// append the chainId to the list
chainIds.push(_chainId);

// initialize each contracts by calling `initialize` functions through proxys
_initializeSystemConfig(_cfg, proxyAdmin, impls[2], proxys);
Expand All @@ -155,11 +176,6 @@ contract L1BuildAgent is IL1BuildAgent, ISemver {
// transfer ownership of the proxy admin to the final system owner
_transferProxyAdminOwnership(_cfg, proxyAdmin);

// register `SystemConfig` proxy address to `chainSystemConfig`
chainSystemConfig[_chainId] = proxys[2];
// append the chainId to the list
chainIds.push(_chainId);

return (address(proxyAdmin), proxys, impls, batchInbox, addressManager);
}

Expand All @@ -183,7 +199,7 @@ contract L1BuildAgent is IL1BuildAgent, ISemver {
}

function _isInternallyUniqueChainId(uint256 _chainId) internal view returns (bool) {
return chainSystemConfig[_chainId] == address(0);
return builders[_chainId] == address(0);
}

function _requiresDepositCheck(uint256 _chainId) internal view returns (bool) {
Expand Down Expand Up @@ -332,9 +348,9 @@ contract L1BuildAgent is IL1BuildAgent, ISemver {
_owner: _cfg.finalSystemOwner,
_batcherHash: bytes32(uint256(uint160(_cfg.batchSenderAddress))),
_config: Constants.DEFAULT_RESOURCE_CONFIG(),
// This is originally `p2pSequencerAddress` which sign the block for p2p propagation
// Don't distinguish between sequencer and p2pSequencerAddress(=unsafeBlockSigner)
_unsafeBlockSigner: _cfg.l2OutputOracleProposer,
// unsafeBlockSigner is same as p2pSequencerAddress
// This address signs the unsafe block. The signed unsafe block is broadcasted to other p2p peers.
_unsafeBlockSigner: _cfg.p2pSequencerAddress,
// gasPriceOracleOverhead
// The rollup gas of L2 txs batch is calculated by the size of L2 data. This overhead is added to it.
// The value bellow is the same as the value of the Opstack Mainnet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ interface IL1BuildAgent {
// The address of the l2 transaction batch sender. This address is recorded in SystemConfig contract.
// Value: depending on each verse
address batchSenderAddress;
// The address of the p2p sequencer. This address is recorded in SystemConfig contract.
// This address sign the block for p2p sync.
// Value: depending on each verse
address p2pSequencerAddress;
// the block time of l2 chain
// Value: 2s
uint256 l2BlockTime;
Expand Down Expand Up @@ -43,8 +47,23 @@ interface IL1BuildAgent {
uint256 l2OutputOracleStartingTimestamp;
}

/// @notice The address list of the built L1 contract set
struct BuiltAddressList {
address proxyAdmin;
address systemConfig;
address l1StandardBridge;
address l1ERC721Bridge;
address l1CrossDomainMessenger;
address oasysL2OutputOracle;
address oasysPortal;
address protocolVersions;
address batchInbox;
address addressManager;
}

/// @notice Event emitted when the L1 contract set is deployed
event Deployed(
uint256 indexed chainId,
address owner,
address proxyAdmin,
address[7] proxys,
Expand All @@ -53,7 +72,7 @@ interface IL1BuildAgent {
address addressManager
);

function chainSystemConfig(uint256 chainId) external view returns (address systemConfig);
function builtLists(uint256 chainId) external view returns (address, address, address, address, address, address, address, address, address, address);

function chainIds(uint256 index) external view returns (uint256 chainId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ contract OasysPortal is OptimismPortal {
/// @return Whether or not the finalization period has elapsed.
function _isFinalizationPeriodElapsed(uint256 _timestamp) internal view override returns (bool) {
if (messageRelayer != address(0) && msg.sender == messageRelayer) {
// NOTE:
// The `_timestamp` is the timestamp of prove tx, not the one of the L2 withdrawal state root.
// Although the original schema of instant verification verifies the state root of the L2 withdrawal tx,
// we wait until the verified timestamp overtakes the proposed L2 state root timestamp.
// This decision is made to address security threats that OpStack is considering.
// OpStack separates withdrawals into two steps to counteract fraudulent proofs of withdrawal.
// We are following this approach to allow room for opposition,
// Therefore, we wait based on the proven tx timestamp.
// Ref: https://github.com/oasysgames/oasys-opstack/issues/118
//slither-disable-next-line calls-inside-a-loop
uint256 verified = IOasysL2OutputOracle(address(L2_ORACLE)).verifiedL1Timestamp();
if (verified > _timestamp) {
Expand Down

0 comments on commit 289f773

Please sign in to comment.