@@ -4,6 +4,7 @@ pragma solidity 0.8.28;
44import {LibClone} from "solady/utils/LibClone.sol " ;
55import {ReentrancyGuardTransient} from "solady/utils/ReentrancyGuardTransient.sol " ;
66import {UpgradeableBeacon} from "solady/utils/UpgradeableBeacon.sol " ;
7+ import {Initializable} from "solady/utils/Initializable.sol " ;
78
89import {Call} from "./libraries/CallLib.sol " ;
910import {IncomingMessage, MessageType} from "./libraries/MessageLib.sol " ;
@@ -20,7 +21,7 @@ import {Twin} from "./Twin.sol";
2021/// @notice The Bridge enables sending calls from Solana to Base.
2122///
2223/// @dev Calls sent from Solana to Base are relayed via a Twin contract that is specific per Solana sender pubkey.
23- contract Bridge is ReentrancyGuardTransient {
24+ contract Bridge is ReentrancyGuardTransient , Initializable {
2425 //////////////////////////////////////////////////////////////
2526 /// Constants ///
2627 //////////////////////////////////////////////////////////////
@@ -56,33 +57,37 @@ contract Bridge is ReentrancyGuardTransient {
5657 ///
5758 uint256 private constant _EXECUTION_PROLOGUE_GAS_BUFFER = 35_000 ;
5859
59- /// @notice Gas required to run the execution section of `__validateAndRelay`.
60+ /// @notice Gas required to run the execution epilogue section of `__validateAndRelay`.
6061 ///
61- /// @dev Simulated via a forge test performing a single call to `__validateAndRelay` where:
62- /// - The execution epilogue section was commented out to isolate the execution section.
62+ /// @dev Simulated via a forge test performing a call to `relayMessages` with a single message where:
63+ /// - The execution prologue and the execution sections were commented out to isolate the execution epilogue
64+ /// section.
65+ /// - `isTrustedRelayer` was true to estimate the worst case scenario of doing an additional SSTORE.
6366 /// - The `message.data` field was 4KB large which is sufficient given that the message has to be built from a
6467 /// single Solana transaction (which currently is 1232 bytes).
65- /// - The metered gas (including the execution prologue section) was 32,858 gas thus the isolated
66- /// execution section was 32,858 - 30,252 = 2,606 gas.
67- /// - No buffer is strictly needed as the `_EXECUTION_PROLOGUE_GAS_BUFFER` is already rounded up and above
68- /// that.
69- uint256 private constant _EXECUTION_GAS_BUFFER = 3_000 ;
68+ /// - The metered gas was 6,458 gas.
69+ ///
70+ uint256 private constant _EXECUTION_EPILOGUE_GAS_BUFFER = 10_000 ;
7071
71- /// @notice Gas required to run the execution epilogue section of `__validateAndRelay`.
72+ /// @notice Gas buffer required to execute the try-catch in `__validateAndRelay` and run the catch block .
7273 ///
73- /// @dev Simulated via a forge test performing a single call to `__validateAndRelay` where:
74- /// - The `message.data` field was 4KB large which is sufficient given that the message has to be built from a
75- /// single Solana transaction (which currently is 1232 bytes).
76- /// - The metered gas (including the execution prologue and execution sections) was 54,481 gas thus the
77- /// isolated execution epilogue section was 54,481 - 32,858 = 21,623 gas.
78- uint256 private constant _EXECUTION_EPILOGUE_GAS_BUFFER = 25_000 ;
74+ /// @dev Computed based on the following formula:
75+ /// `_EXECUTION_GAS_BUFFER = _EXECUTION_PROLOGUE_GAS_BUFFER + _EXECUTION_EPILOGUE_GAS_BUFFER + catch_block_gas`
76+ /// Where the `catch_block_gas` is roughly 5,000 gas.
77+ ///
78+ uint256 private constant _EXECUTION_GAS_BUFFER = 50_000 ;
7979
8080 //////////////////////////////////////////////////////////////
8181 /// Storage ///
8282 //////////////////////////////////////////////////////////////
8383
84- /// @notice Mapping of message hashes to boolean values indicating successful execution. A message will only be
85- /// present in this mapping if it has successfully been executed, and therefore cannot be executed again.
84+ /// @notice The nonce of the last MMR root for a given block number. This provides efficient access to the
85+ /// currently active roots for fast-lane optimization without double-inclusion proofs.
86+ mapping (uint256 blockNumber = > uint256 nonce ) public latestRootNonces;
87+
88+ /// @notice Mapping of message hashes to boolean values indicating successful execution. A message hash will be
89+ /// present in this mapping if and only if it has been successfully executed (including during failed
90+ /// transactions that were later manually retried by users).
8691 mapping (bytes32 messageHash = > bool success ) public successes;
8792
8893 /// @notice Mapping of message hashes to boolean values indicating failed execution attempts. A message will be
@@ -153,23 +158,31 @@ contract Bridge is ReentrancyGuardTransient {
153158 /// @param trustedRelayer The address of the trusted relayer.
154159 /// @param twinBeacon The address of the Twin beacon.
155160 /// @param crossChainErc20Factory The address of the CrossChainERC20Factory.
156- /// @param validators Array of validator addresses for ISM verification.
157- /// @param threshold The ISM verification threshold.
158- /// @param ismOwner The owner of the ISM verification system.
159161 constructor (
160162 Pubkey remoteBridge ,
161163 address trustedRelayer ,
162164 address twinBeacon ,
163- address crossChainErc20Factory ,
164- address [] memory validators ,
165- uint128 threshold ,
166- address ismOwner
165+ address crossChainErc20Factory
167166 ) {
168167 REMOTE_BRIDGE = remoteBridge;
169168 TRUSTED_RELAYER = trustedRelayer;
170169 TWIN_BEACON = twinBeacon;
171170 CROSS_CHAIN_ERC20_FACTORY = crossChainErc20Factory;
172-
171+ }
172+
173+ /// @notice Initializes the Bridge contract with ISM verification parameters.
174+ ///
175+ /// @dev This function should be called immediately after deployment when using with a proxy.
176+ /// Can only be called once due to the initializer modifier.
177+ ///
178+ /// @param validators Array of validator addresses for ISM verification.
179+ /// @param threshold The ISM verification threshold.
180+ /// @param ismOwner The owner of the ISM verification system.
181+ function initialize (
182+ address [] memory validators ,
183+ uint128 threshold ,
184+ address ismOwner
185+ ) external initializer {
173186 // Initialize ISM verification library
174187 ISMVerificationLib.initialize (validators, threshold, ismOwner);
175188 }
0 commit comments