Skip to content

Commit

Permalink
Merge pull request #17 from lightclient/add-event
Browse files Browse the repository at this point in the history
Add logging to system contracts
  • Loading branch information
lightclient authored Aug 20, 2024
2 parents dea4517 + d338503 commit ee61e80
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
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

0 comments on commit ee61e80

Please sign in to comment.