Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logging to system contracts #17

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/consolidations/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,23 @@ check_input:
swap1 ;; [slot, target[16:48], ..]
sstore ;; [..]


;; Assemble log data.
caller ;; [caller, ..]
push1 96 ;; [96, caller, ..]
shl ;; [caller, ..]
push0 ;; [0, caller, ..]
mstore ;; [..]
push1 INPUT_SIZE ;; [size, ..]
push0 ;; [ost, size, ..]
push1 20 ;; [dest, ost, size, ..]
calldatacopy ;; [..]

;; Log record.
push1 RECORD_SIZE ;; [size, ..]
push0 ;; [idx, size, ..]
log0 ;; [..]

;; Increment queue tail over last and write to storage.
push1 1 ;; [1, tail_idx]
add ;; [tail_idx+1]
Expand Down
16 changes: 16 additions & 0 deletions src/withdrawals/main.eas
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ check_input:
swap1 ;; [slot, pk2_am, ..]
sstore ;; [..]

;; Assemble log data.
caller ;; [caller, ..]
push1 96 ;; [96, caller, ..]
shl ;; [caller, ..]
push0 ;; [0, caller, ..]
mstore ;; [..]
push1 INPUT_SIZE ;; [size, ..]
push0 ;; [ost, size, ..]
push1 20 ;; [dest, ost, size, ..]
calldatacopy ;; [..]

;; Log record.
push1 RECORD_SIZE ;; [size, ..]
push0 ;; [idx, size, ..]
log0 ;; [..]

;; Increment queue tail over last and write to storage.
push1 1 ;; [1, tail_idx]
add ;; [tail_idx+1]
Expand Down
13 changes: 12 additions & 1 deletion test/Consolidation.t.sol.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ contract ConsolidationTest is Test {
// request count is accepted and read successfully.
function testConsolidation() public {
bytes memory data = hex"111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222";

vm.expectEmitAnonymous(false, false, false, false, true);
assembly {
let ptr := mload(0x40)
mstore(ptr, shl(96, address()))
mstore(add(ptr, 20), mload(add(data, 32)))
mstore(add(ptr, 52), mload(add(data, 64)))
mstore(add(ptr, 84), mload(add(data, 96)))
log0(ptr, 116)
}

(bool ret,) = addr.call{value: 2}(data);
assertEq(ret, true);
assertEq(ret, true, "call failed");
assertStorage(count_slot, 1, "unexpected request count");
assertExcess(0);

Expand Down
10 changes: 10 additions & 0 deletions test/Withdrawal.t.sol.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ contract WithdrawalsTest is Test {
// count is accepted and read successfully.
function testWithdrawal() public {
bytes memory data = hex"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222222222";

vm.expectEmitAnonymous(false, false, false, false, true);
assembly {
let ptr := mload(0x40)
mstore(ptr, shl(96, address()))
mstore(add(ptr, 20), mload(add(data, 32)))
mstore(add(ptr, 52), mload(add(data, 64)))
log0(ptr, 76)
}

(bool ret,) = addr.call{value: 2}(data);
assertEq(ret, true);
assertStorage(count_slot, 1, "unexpected request count");
Expand Down
Loading