From 493bf8565badf1f74f04f23aab44bf191a498815 Mon Sep 17 00:00:00 2001 From: lightclient Date: Mon, 30 Sep 2024 13:28:31 -0600 Subject: [PATCH 1/2] wx,cx: gate pre-fork requests on max uint256 excess inhibitor --- src/consolidations/ctor.eas | 7 +++---- src/consolidations/main.eas | 9 ++++++++- src/withdrawals/ctor.eas | 7 +++---- src/withdrawals/main.eas | 9 ++++++++- test/Consolidation.t.sol.in | 7 ++++--- test/Withdrawal.t.sol.in | 10 +++++++--- 6 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/consolidations/ctor.eas b/src/consolidations/ctor.eas index 76e5f4f..41aa941 100644 --- a/src/consolidations/ctor.eas +++ b/src/consolidations/ctor.eas @@ -1,7 +1,6 @@ -;; Store 1181 as a temporary excess value as it creates a fee so large that no -;; request will be accepted in the queue until after 7002 is activated and -;; called by the system for the first time. -push 1181 +;; Store 0xff..ff as a temporary excess value to avoid requests being queued +;; before the fork. +push 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff push0 sstore diff --git a/src/consolidations/main.eas b/src/consolidations/main.eas index b082e3a..a37ec01 100644 --- a/src/consolidations/main.eas +++ b/src/consolidations/main.eas @@ -24,7 +24,7 @@ #define TARGET_PER_BLOCK 1 #define MAX_PER_BLOCK 1 #define FEE_UPDATE_FRACTION 17 -#define EXCESS_INHIBITOR 1181 +#define EXCESS_INHIBITOR 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff #define INPUT_SIZE 96 ;; the size of (source ++ target) #define RECORD_SIZE 116 ;; the size of (address ++ source ++ target) @@ -84,6 +84,13 @@ check_input: push FEE_UPDATE_FRACTION push SLOT_EXCESS ;; [excess_slot, update_fraction] sload ;; [excess, update_fraction] + + ;; Check if the pre-fork inhibitor is still active, revert if so. + dup1 ;; [excess, excess, update_fraction] + push EXCESS_INHIBITOR ;; [inhibitor, excess, excess, update_fraction] + eq ;; [inhibitor == excess, excess, update_fraction] + jumpi @revert ;; [excess, update_fraction] + push MIN_FEE ;; [min_fee, excess, update_fraction] #include "../common/fake_expo.eas" diff --git a/src/withdrawals/ctor.eas b/src/withdrawals/ctor.eas index 76e5f4f..41aa941 100644 --- a/src/withdrawals/ctor.eas +++ b/src/withdrawals/ctor.eas @@ -1,7 +1,6 @@ -;; Store 1181 as a temporary excess value as it creates a fee so large that no -;; request will be accepted in the queue until after 7002 is activated and -;; called by the system for the first time. -push 1181 +;; Store 0xff..ff as a temporary excess value to avoid requests being queued +;; before the fork. +push 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff push0 sstore diff --git a/src/withdrawals/main.eas b/src/withdrawals/main.eas index 0e6ff6f..ba90e2e 100644 --- a/src/withdrawals/main.eas +++ b/src/withdrawals/main.eas @@ -34,7 +34,7 @@ #define TARGET_PER_BLOCK 2 #define MAX_PER_BLOCK 16 #define FEE_UPDATE_FRACTION 17 -#define EXCESS_INHIBITOR 1181 +#define EXCESS_INHIBITOR 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff #define INPUT_SIZE 56 ;; the size of (pubkey ++ amount) #define RECORD_SIZE 76 ;; the size of (address ++ pubkey ++ amount) @@ -94,6 +94,13 @@ check_input: push FEE_UPDATE_FRACTION push SLOT_EXCESS ;; [excess_slot, update_fraction] sload ;; [excess, update_fraction] + + ;; Check if the pre-fork inhibitor is still active, revert if so. + dup1 ;; [excess, excess, update_fraction] + push EXCESS_INHIBITOR ;; [inhibitor, excess, excess, update_fraction] + eq ;; [inhibitor == excess, excess, update_fraction] + jumpi @revert ;; [excess, update_fraction] + push MIN_FEE ;; [min_fee, excess, update_fraction] #include "../common/fake_expo.eas" diff --git a/test/Consolidation.t.sol.in b/test/Consolidation.t.sol.in index f779ea6..0cc2006 100644 --- a/test/Consolidation.t.sol.in +++ b/test/Consolidation.t.sol.in @@ -5,6 +5,7 @@ import "./Test.sol"; uint256 constant target_per_block = 1; uint256 constant max_per_block = 1; +uint256 constant inhibitor = uint256(bytes32(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)); contract ConsolidationTest is Test { @@ -146,15 +147,15 @@ contract ConsolidationTest is Test { // testInhibitorRest verifies that after the first system call the excess // value is reset to 0. function testInhibitorReset() public { - vm.store(addr, bytes32(0), bytes32(uint256(1181))); + vm.store(addr, bytes32(0), bytes32(inhibitor)); vm.prank(sysaddr); (bool ret, bytes memory data) = addr.call(""); assertStorage(excess_slot, 0, "expected excess requests to be reset"); - vm.store(addr, bytes32(0), bytes32(uint256(1180))); + vm.store(addr, bytes32(0), bytes32(inhibitor-1)); vm.prank(sysaddr); (ret, data) = addr.call(""); - assertStorage(excess_slot, 1180-target_per_block, "didn't expect excess to be reset"); + assertStorage(excess_slot, inhibitor-target_per_block-1, "didn't expect excess to be reset"); } // -------------------------------------------------------------------------- diff --git a/test/Withdrawal.t.sol.in b/test/Withdrawal.t.sol.in index faabad9..b20ae17 100644 --- a/test/Withdrawal.t.sol.in +++ b/test/Withdrawal.t.sol.in @@ -5,6 +5,7 @@ import "./Test.sol"; uint256 constant target_per_block = 2; uint256 constant max_per_block = 16; +uint256 constant inhibitor = uint256(bytes32(0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)); contract WithdrawalsTest is Test { address unit; @@ -147,15 +148,18 @@ contract WithdrawalsTest is Test { // testInhibitorRest verifies that after the first system call the excess // value is reset to 0. function testInhibitorReset() public { - vm.store(addr, bytes32(0), bytes32(uint256(1181))); + vm.store(addr, bytes32(0), bytes32(inhibitor)); vm.prank(sysaddr); (bool ret, bytes memory data) = addr.call(""); assertStorage(excess_slot, 0, "expected excess requests to be reset"); - vm.store(addr, bytes32(0), bytes32(uint256(1180))); + vm.store(addr, bytes32(0), bytes32(inhibitor)); + addFailedRequest(address(uint160(0)), makeWithdrawal(0), inhibitor); + + vm.store(addr, bytes32(0), bytes32(inhibitor-1)); vm.prank(sysaddr); (ret, data) = addr.call(""); - assertStorage(excess_slot, 1180-target_per_block, "didn't expect excess to be reset"); + assertStorage(excess_slot, inhibitor-target_per_block-1, "didn't expect excess to be reset"); } // -------------------------------------------------------------------------- From f7c5f1f5753d13934cb0b9f28f68ee8d80957d8f Mon Sep 17 00:00:00 2001 From: lightclient Date: Mon, 30 Sep 2024 13:35:49 -0600 Subject: [PATCH 2/2] consolidations: add test case for submitting failed request pre-fork --- test/Consolidation.t.sol.in | 5 ++++- test/Withdrawal.t.sol.in | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/test/Consolidation.t.sol.in b/test/Consolidation.t.sol.in index 0cc2006..8678b0b 100644 --- a/test/Consolidation.t.sol.in +++ b/test/Consolidation.t.sol.in @@ -144,7 +144,7 @@ contract ConsolidationTest is Test { } - // testInhibitorRest verifies that after the first system call the excess + // testInhibitorReset verifies that after the first system call the excess // value is reset to 0. function testInhibitorReset() public { vm.store(addr, bytes32(0), bytes32(inhibitor)); @@ -152,6 +152,9 @@ contract ConsolidationTest is Test { (bool ret, bytes memory data) = addr.call(""); assertStorage(excess_slot, 0, "expected excess requests to be reset"); + vm.store(addr, bytes32(0), bytes32(inhibitor)); + addFailedRequest(address(uint160(0)), makeConsolidation(0), inhibitor); + vm.store(addr, bytes32(0), bytes32(inhibitor-1)); vm.prank(sysaddr); (ret, data) = addr.call(""); diff --git a/test/Withdrawal.t.sol.in b/test/Withdrawal.t.sol.in index b20ae17..e229901 100644 --- a/test/Withdrawal.t.sol.in +++ b/test/Withdrawal.t.sol.in @@ -145,7 +145,7 @@ contract WithdrawalsTest is Test { } - // testInhibitorRest verifies that after the first system call the excess + // testInhibitorReset verifies that after the first system call the excess // value is reset to 0. function testInhibitorReset() public { vm.store(addr, bytes32(0), bytes32(inhibitor));