From 8cf5cf5f876e74f456ffaf4d621e4bc5003c8509 Mon Sep 17 00:00:00 2001 From: niha <205694301+0xniha@users.noreply.github.com> Date: Mon, 18 Aug 2025 16:13:10 -0300 Subject: [PATCH 1/2] feat: add withdrawal network type check on fee vaults deploy --- .../contracts-bedrock/scripts/L2Genesis.s.sol | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/contracts-bedrock/scripts/L2Genesis.s.sol b/packages/contracts-bedrock/scripts/L2Genesis.s.sol index ef18c52dcb065..607ca1815369f 100644 --- a/packages/contracts-bedrock/scripts/L2Genesis.s.sol +++ b/packages/contracts-bedrock/scripts/L2Genesis.s.sol @@ -298,6 +298,12 @@ contract L2Genesis is Script { /// @notice This predeploy is following the safety invariant #2, function setSequencerFeeVault(Input memory _input) internal { + Types.WithdrawalNetwork withdrawalNetwork = Types.WithdrawalNetwork(_input.sequencerFeeVaultWithdrawalNetwork); + + if (_input.isCustomGasToken && withdrawalNetwork == Types.WithdrawalNetwork.L1) { + revert("SequencerFeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); + } + ISequencerFeeVault vault = ISequencerFeeVault( DeployUtils.create1({ _name: "SequencerFeeVault", @@ -307,7 +313,7 @@ contract L2Genesis is Script { ( _input.sequencerFeeVaultRecipient, _input.sequencerFeeVaultMinimumWithdrawalAmount, - Types.WithdrawalNetwork(_input.sequencerFeeVaultWithdrawalNetwork) + withdrawalNetwork ) ) ) @@ -402,17 +408,19 @@ contract L2Genesis is Script { /// @notice This predeploy is following the safety invariant #2. function setBaseFeeVault(Input memory _input) internal { + Types.WithdrawalNetwork withdrawalNetwork = Types.WithdrawalNetwork(_input.baseFeeVaultWithdrawalNetwork); + + if (_input.isCustomGasToken && withdrawalNetwork == Types.WithdrawalNetwork.L1) { + revert("BaseFeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); + } + IBaseFeeVault vault = IBaseFeeVault( DeployUtils.create1({ _name: "BaseFeeVault", _args: DeployUtils.encodeConstructor( abi.encodeCall( IBaseFeeVault.__constructor__, - ( - _input.baseFeeVaultRecipient, - _input.baseFeeVaultMinimumWithdrawalAmount, - Types.WithdrawalNetwork(_input.baseFeeVaultWithdrawalNetwork) - ) + (_input.baseFeeVaultRecipient, _input.baseFeeVaultMinimumWithdrawalAmount, withdrawalNetwork) ) ) }) @@ -428,17 +436,19 @@ contract L2Genesis is Script { /// @notice This predeploy is following the safety invariant #2. function setL1FeeVault(Input memory _input) internal { + Types.WithdrawalNetwork withdrawalNetwork = Types.WithdrawalNetwork(_input.l1FeeVaultWithdrawalNetwork); + + if (_input.isCustomGasToken && withdrawalNetwork == Types.WithdrawalNetwork.L1) { + revert("L1FeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); + } + IL1FeeVault vault = IL1FeeVault( DeployUtils.create1({ _name: "L1FeeVault", _args: DeployUtils.encodeConstructor( abi.encodeCall( IL1FeeVault.__constructor__, - ( - _input.l1FeeVaultRecipient, - _input.l1FeeVaultMinimumWithdrawalAmount, - Types.WithdrawalNetwork(_input.l1FeeVaultWithdrawalNetwork) - ) + (_input.l1FeeVaultRecipient, _input.l1FeeVaultMinimumWithdrawalAmount, withdrawalNetwork) ) ) }) From 89aa1348b947eb9b7837ffad8b4ded26d1333886 Mon Sep 17 00:00:00 2001 From: niha <205694301+0xniha@users.noreply.github.com> Date: Mon, 18 Aug 2025 17:17:54 -0300 Subject: [PATCH 2/2] test: add l2genesis revert test cases for invalid withdrawal network types --- .../test/scripts/L2Genesis.t.sol | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol b/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol index b8553a57a1043..9f7f86a14ded8 100644 --- a/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol +++ b/packages/contracts-bedrock/test/scripts/L2Genesis.t.sol @@ -160,7 +160,8 @@ contract L2Genesis_Run_Test is L2Genesis_TestInit { testForks(); } - function test_run_cgt_succeeds() external { + /// @dev Modifier to set up the input for L2Genesis with CGT enabled. + modifier setInputCGTEnabled() { input = L2Genesis.Input({ l1ChainID: 1, l2ChainID: 2, @@ -186,6 +187,12 @@ contract L2Genesis_Run_Test is L2Genesis_TestInit { gasPayingTokenName: "Custom Gas Token", gasPayingTokenSymbol: "CGT" }); + _; + } + + /// @notice Tests that the run function succeeds when CGT is enabled. + /// @dev Tests that LiquidityController and NativeAssetLiquidity are deployed. + function test_run_cgt_succeeds() external setInputCGTEnabled { genesis.run(input); testProxyAdmin(); @@ -196,4 +203,27 @@ contract L2Genesis_Run_Test is L2Genesis_TestInit { testForks(); testCGT(); } + + /// @notice Tests that the run function reverts when CGT is enabled and the withdrawal network type of the FeeVaults + /// is L1. + function test_run_cgt_reverts() external setInputCGTEnabled { + // Expect revert when sequencerFeeVaultWithdrawalNetwork is L1 + input.sequencerFeeVaultWithdrawalNetwork = 0; + vm.expectRevert("SequencerFeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); + genesis.run(input); + // Reset sequencerFeeVaultWithdrawalNetwork input to L2 + input.sequencerFeeVaultWithdrawalNetwork = 1; + + // Expect revert when baseFeeVaultWithdrawalNetwork is L1 + input.baseFeeVaultWithdrawalNetwork = 0; + vm.expectRevert("BaseFeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); + genesis.run(input); + // Reset baseFeeVaultWithdrawalNetwork input to L2 + input.baseFeeVaultWithdrawalNetwork = 1; + + // Expect revert when l1FeeVaultWithdrawalNetwork is L1 + input.l1FeeVaultWithdrawalNetwork = 0; + vm.expectRevert("L1FeeVault: withdrawalNetwork type cannot be L1 when custom gas token is enabled"); + genesis.run(input); + } }