Skip to content

Commit

Permalink
compensate for balance inquiries beyond the delay window
Browse files Browse the repository at this point in the history
  • Loading branch information
just-mitch committed Sep 29, 2024
1 parent 717947d commit 1450cd1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
11 changes: 10 additions & 1 deletion l1-contracts/src/core/ProofCommitmentEscrow.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Aztec Labs.
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {SafeERC20} from "@oz/token/ERC20/utils/SafeERC20.sol";
Expand Down Expand Up @@ -124,6 +124,8 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {
/**
* @notice Get the minimum balance of a prover at a given timestamp.
*
* @dev Returns 0 if the timestamp is beyond the WITHDRAW_DELAY from the current block timestamp
*
* @param _timestamp The timestamp at which to check the balance
* @param _prover The address of the prover
*
Expand All @@ -135,6 +137,13 @@ contract ProofCommitmentEscrow is IProofCommitmentEscrow {
override
returns (uint256)
{
// If the timestamp is beyond the WITHDRAW_DELAY, the minimum possible balance is 0;
// the prover could issue a withdraw request in this block for the full amount,
// and execute it exactly WITHDRAW_DELAY later.
if (_timestamp >= block.timestamp + WITHDRAW_DELAY) {
return 0;
}

uint256 balance = deposits[_prover];
if (withdrawRequests[_prover].executableAt <= _timestamp) {
balance -= withdrawRequests[_prover].amount;
Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Aztec Labs.
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {IProofCommitmentEscrow} from "@aztec/core/interfaces/IProofCommitmentEscrow.sol";
Expand Down
3 changes: 1 addition & 2 deletions l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Aztec Labs.
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {DecoderBase} from "./decoders/Base.sol";
import {console} from "forge-std/console.sol";

import {DataStructures} from "@aztec/core/libraries/DataStructures.sol";
import {Constants} from "@aztec/core/libraries/ConstantsGen.sol";
Expand Down
3 changes: 1 addition & 2 deletions l1-contracts/test/prover-coordination/EscrowERC20.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// docs:start:contract
// Copyright 2024 Aztec Labs.
pragma solidity ^0.8.27;

import {ERC20} from "@oz/token/ERC20/ERC20.sol";
Expand All @@ -13,4 +13,3 @@ contract EscrowERC20 is ERC20 {
_mint(to, amount);
}
}
// docs:end:contract
20 changes: 17 additions & 3 deletions l1-contracts/test/prover-coordination/ProofCommitmentEscrow.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Aztec Labs.
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {Test} from "forge-std/Test.sol";
Expand Down Expand Up @@ -271,7 +271,7 @@ contract TestProofCommitmentEscrow is Test {
);

assertEq(
_escrow.minBalanceAtTime(withdrawReadyAt, prover),
_escrow.minBalanceAtTime(withdrawReadyAt - 1, prover),
depositAmount,
"Min balance should match deposit amount before withdraw request matures"
);
Expand All @@ -285,10 +285,24 @@ contract TestProofCommitmentEscrow is Test {
"Min balance should be unaffected by pending withdraw request before maturity"
);

assertEq(
_escrow.minBalanceAtTime(block.timestamp + _escrow.WITHDRAW_DELAY(), prover),
0,
"Min balance should be 0 at or beyond the delay window"
);

vm.warp(block.timestamp + 1);

assertEq(
_escrow.minBalanceAtTime(withdrawReadyAt, prover),
depositAmount - withdrawAmount,
"Min balance should reflect pending withdraw request after maturity"
"Min balance should be 75 after withdraw request matures"
);

assertEq(
_escrow.minBalanceAtTime(withdrawReadyAt + 1, prover),
0,
"Min balance should be 0 at or beyond the delay window"
);
}

Expand Down
2 changes: 1 addition & 1 deletion l1-contracts/test/prover-coordination/Signatures.t.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2023 Aztec Labs.
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.27;

import {Test} from "forge-std/Test.sol";
Expand Down

0 comments on commit 1450cd1

Please sign in to comment.