Skip to content

Commit

Permalink
Merge pull request #26 from lightclient/fee-gate
Browse files Browse the repository at this point in the history
Gate pre-fork requests on max uint256 excess inhibitor
  • Loading branch information
lightclient authored Oct 1, 2024
2 parents 0ff405f + f7c5f1f commit a78e84e
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 18 deletions.
7 changes: 3 additions & 4 deletions src/consolidations/ctor.eas
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/consolidations/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"

Expand Down
7 changes: 3 additions & 4 deletions src/withdrawals/ctor.eas
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 8 additions & 1 deletion src/withdrawals/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"

Expand Down
12 changes: 8 additions & 4 deletions test/Consolidation.t.sol.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -143,18 +144,21 @@ 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(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)), makeConsolidation(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");
}

// --------------------------------------------------------------------------
Expand Down
12 changes: 8 additions & 4 deletions test/Withdrawal.t.sol.in
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -144,18 +145,21 @@ 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(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");
}

// --------------------------------------------------------------------------
Expand Down

0 comments on commit a78e84e

Please sign in to comment.