From e22c77e18df4f6fe814cc317bab7f08da7271e8c Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Fri, 17 Jan 2025 16:10:36 -0500 Subject: [PATCH 1/2] chore: fixes edge case lack of logging --- contracts/contracts/core/BidderRegistry.sol | 11 ++++- contracts/lib/burners | 2 +- contracts/lib/core | 2 +- contracts/test/core/BidderRegistryTest.sol | 50 +++++++++++++++++++-- 4 files changed, 57 insertions(+), 8 deletions(-) diff --git a/contracts/contracts/core/BidderRegistry.sol b/contracts/contracts/core/BidderRegistry.sol index a8125e522..e5f9e7906 100644 --- a/contracts/contracts/core/BidderRegistry.sol +++ b/contracts/contracts/core/BidderRegistry.sol @@ -128,6 +128,8 @@ contract BidderRegistry is ) external nonReentrant whenNotPaused { uint256 currentWindow = blockTrackerContract.getCurrentWindow(); uint256 totalAmount; + uint256[] memory withdrawnWindows = new uint256[](windows.length); + uint256[] memory withdrawnAmounts = new uint256[](windows.length); uint256 len = windows.length; for (uint256 i = 0; i < len; ++i) { @@ -145,13 +147,18 @@ contract BidderRegistry is usedFunds[msg.sender][uint64(blockNumber)] = 0; } - emit BidderWithdrawal(msg.sender, window, amount); - + withdrawnWindows[i] = window; + withdrawnAmounts[i] = amount; totalAmount += amount; } (bool success, ) = msg.sender.call{value: totalAmount}(""); require(success, BidderWithdrawalTransferFailed(msg.sender, totalAmount)); + + // Emit events only after successful transfer + for (uint256 i = 0; i < len; ++i) { + emit BidderWithdrawal(msg.sender, withdrawnWindows[i], withdrawnAmounts[i]); + } } /** diff --git a/contracts/lib/burners b/contracts/lib/burners index c5840718d..60a5eb87f 160000 --- a/contracts/lib/burners +++ b/contracts/lib/burners @@ -1 +1 @@ -Subproject commit c5840718d3ebf79500b420e5f082e4f8a4363d48 +Subproject commit 60a5eb87f196b62d48406b45cc3b19ef4be0e906 diff --git a/contracts/lib/core b/contracts/lib/core index 106d10bcc..5061e30ba 160000 --- a/contracts/lib/core +++ b/contracts/lib/core @@ -1 +1 @@ -Subproject commit 106d10bcc77c9e1a1d2cd041f6840009ed135692 +Subproject commit 5061e30ba6866680d3a9a2b1a4c52f6cb95dc9fc diff --git a/contracts/test/core/BidderRegistryTest.sol b/contracts/test/core/BidderRegistryTest.sol index a68ff7e62..f6a9318a6 100644 --- a/contracts/test/core/BidderRegistryTest.sol +++ b/contracts/test/core/BidderRegistryTest.sol @@ -19,13 +19,17 @@ contract BidderRegistryTest is Test { uint256 public feePayoutPeriodBlocks; BlockTracker public blockTracker; ProviderRegistry public providerRegistry; + address public oracleAccount; - /// @dev Event emitted when a bidder is registered with their staked amount - event BidderRegistered(address indexed bidder, uint256 indexed stakedAmount, uint256 indexed windowNumber); - + event BidderRegistered( + address indexed bidder, + uint256 indexed depositedAmount, + uint256 indexed windowNumber + ); event FeeTransfer(uint256 amount, address indexed recipient); event ProtocolFeeRecipientUpdated(address indexed newProtocolFeeRecipient); event FeePayoutPeriodBlocksUpdated(uint256 indexed newFeePayoutPeriodBlocks); + event BidderWithdrawal(address indexed bidder, uint256 indexed window, uint256 indexed amount); function setUp() public { testNumber = 42; @@ -33,9 +37,10 @@ contract BidderRegistryTest is Test { minStake = 1e18 wei; feeRecipient = vm.addr(9); feePayoutPeriodBlocks = 100; + oracleAccount = address(this); address blockTrackerProxy = Upgrades.deployUUPSProxy( "BlockTracker.sol", - abi.encodeCall(BlockTracker.initialize, (address(this), address(this))) + abi.encodeCall(BlockTracker.initialize, (oracleAccount, address(this))) ); blockTracker = BlockTracker(payable(blockTrackerProxy)); @@ -557,4 +562,41 @@ contract BidderRegistryTest is Test { vm.expectRevert(IBidderRegistry.DepositAmountIsZero.selector); bidderRegistry.depositForWindow{value: 0 ether}(nextWindow); } + + function test_WithdrawFromWindowsEventEmission() public { + uint256 currentWindow = blockTracker.getCurrentWindow(); + uint256 nextWindow = currentWindow + 1; + uint256 depositAmount = 1000000000000000000; + + // Setup: Deposit for two windows + vm.startPrank(bidder); + bidderRegistry.depositForWindow{value: depositAmount}(nextWindow); + bidderRegistry.depositForWindow{value: depositAmount}(nextWindow + 1); + + // Move blocks forward to make windows withdrawable + uint256 newBlockNumber = block.number + WindowFromBlockNumber.BLOCKS_PER_WINDOW * 3; + vm.stopPrank(); + vm.prank(oracleAccount); + blockTracker.recordL1Block(uint64(newBlockNumber), "test"); + + vm.startPrank(bidder); + // Prepare windows array for withdrawal + uint256[] memory windows = new uint256[](2); + windows[0] = nextWindow; + windows[1] = nextWindow + 1; + + // Expect events in order + vm.expectEmit(true, true, true, true); + emit BidderWithdrawal(bidder, nextWindow, depositAmount); + vm.expectEmit(true, true, true, true); + emit BidderWithdrawal(bidder, nextWindow + 1, depositAmount); + + // Perform withdrawal + bidderRegistry.withdrawFromWindows(windows); + vm.stopPrank(); + + // Verify state after withdrawal + assertEq(bidderRegistry.getDeposit(bidder, nextWindow), 0); + assertEq(bidderRegistry.getDeposit(bidder, nextWindow + 1), 0); + } } From ea932d1899bcccf5dbe8a8e208e7d6a402e46186 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Fri, 17 Jan 2025 16:14:27 -0500 Subject: [PATCH 2/2] chore: revert to main branch folder --- contracts/lib/burners | 2 +- contracts/lib/core | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/contracts/lib/burners b/contracts/lib/burners index 60a5eb87f..c5840718d 160000 --- a/contracts/lib/burners +++ b/contracts/lib/burners @@ -1 +1 @@ -Subproject commit 60a5eb87f196b62d48406b45cc3b19ef4be0e906 +Subproject commit c5840718d3ebf79500b420e5f082e4f8a4363d48 diff --git a/contracts/lib/core b/contracts/lib/core index 5061e30ba..106d10bcc 160000 --- a/contracts/lib/core +++ b/contracts/lib/core @@ -1 +1 @@ -Subproject commit 5061e30ba6866680d3a9a2b1a4c52f6cb95dc9fc +Subproject commit 106d10bcc77c9e1a1d2cd041f6840009ed135692