Skip to content

Commit

Permalink
clean up escrow interface
Browse files Browse the repository at this point in the history
remove `TIMELINESS_PROVING_IN_SLOTS`
update tests
  • Loading branch information
just-mitch committed Sep 20, 2024
1 parent 6b1a7ba commit 09d3064
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 60 deletions.
80 changes: 39 additions & 41 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,8 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
uint128 slotNumber;
}

// @note The number of slots within which a block must be proven
// This number is currently pulled out of thin air and should be replaced when we are not blind
// @todo #8018
uint256 public constant TIMELINESS_PROVING_IN_SLOTS = 100;

// See https://github.com/AztecProtocol/engineering-designs/blob/main/in-progress/8401-proof-timeliness/proof-timeliness.ipynb
// for justification of CLAIM_DURATION_IN_L2_SLOTS.
uint256 public constant CLAIM_DURATION_IN_L2_SLOTS = 13;
uint256 public constant PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST = 1000;

Expand Down Expand Up @@ -110,27 +107,6 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
setupEpoch();
}

function status(uint256 myHeaderBlockNumber)
external
view
override(IRollup)
returns (
uint256 provenBlockNumber,
bytes32 provenArchive,
uint256 pendingBlockNumber,
bytes32 pendingArchive,
bytes32 archiveOfMyBlock
)
{
return (
tips.provenBlockNumber,
blocks[tips.provenBlockNumber].archive,
tips.pendingBlockNumber,
blocks[tips.pendingBlockNumber].archive,
archiveAt(myHeaderBlockNumber)
);
}

/**
* @notice Prune the pending chain up to the last proven block
*
Expand Down Expand Up @@ -222,7 +198,7 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
// We don't currently unstake,
// but we will as part of https://github.com/AztecProtocol/aztec-packages/issues/8652.
// Blocked on submitting epoch proofs to this contract.
address bondProvider = PROOF_COMMITMENT_ESCROW.stakeBond(_quote);
address bondProvider = PROOF_COMMITMENT_ESCROW.stakeBond(_quote.signature, _quote.bondAmount);

proofClaim = DataStructures.EpochProofClaim({
epochToProve: epochToProve,
Expand Down Expand Up @@ -452,6 +428,27 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
emit L2ProofVerified(header.globalVariables.blockNumber, _proverId);
}

function status(uint256 myHeaderBlockNumber)
external
view
override(IRollup)
returns (
uint256 provenBlockNumber,
bytes32 provenArchive,
uint256 pendingBlockNumber,
bytes32 pendingArchive,
bytes32 archiveOfMyBlock
)
{
return (
tips.provenBlockNumber,
blocks[tips.provenBlockNumber].archive,
tips.pendingBlockNumber,
blocks[tips.pendingBlockNumber].archive,
archiveAt(myHeaderBlockNumber)
);
}

/**
* @notice Check if msg.sender can propose at a given time
*
Expand Down Expand Up @@ -555,7 +552,22 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
}
}

/**
* @notice Get the archive root of a specific block
*
* @param _blockNumber - The block number to get the archive root of
*
* @return bytes32 - The archive root of the block
*/
function archiveAt(uint256 _blockNumber) public view override(IRollup) returns (bytes32) {
if (_blockNumber <= tips.pendingBlockNumber) {
return blocks[_blockNumber].archive;
}
return bytes32(0);
}

function _prune() internal {
// TODO #8656
delete proofClaim;

uint256 pending = tips.pendingBlockNumber;
Expand Down Expand Up @@ -595,20 +607,6 @@ contract Rollup is Leonidas, IRollup, ITestRollup {
return true;
}

/**
* @notice Get the archive root of a specific block
*
* @param _blockNumber - The block number to get the archive root of
*
* @return bytes32 - The archive root of the block
*/
function archiveAt(uint256 _blockNumber) public view override(IRollup) returns (bytes32) {
if (_blockNumber <= tips.pendingBlockNumber) {
return blocks[_blockNumber].archive;
}
return bytes32(0);
}

/**
* @notice Validates the header for submission
*
Expand Down
8 changes: 5 additions & 3 deletions l1-contracts/src/core/interfaces/IProofCommitmentEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.18;

import {DataStructures} from "../libraries/DataStructures.sol";
import {SignatureLib} from "../libraries/SignatureLib.sol";

interface IProofCommitmentEscrow {
function deposit(uint256 _amount) external;
function withdraw(uint256 _amount) external;
// returns the address of the bond provider
function stakeBond(DataStructures.EpochProofQuote calldata _quote) external returns (address);
function unstakeBond(uint256 _amount) external;
function stakeBond(SignatureLib.Signature calldata _signature, uint256 _bondAmount)
external
returns (address);
function unstakeBond(uint256 _bondAmount) external;
}
1 change: 0 additions & 1 deletion l1-contracts/src/core/libraries/DataStructures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ library DataStructures {
uint256 epochToProve;
uint256 validUntilSlot;
uint256 bondAmount;
address rollup;
uint32 basisPointFee;
}

Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/src/mock/MockProofCommitmentEscrow.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Copyright 2024 Aztec Labs.
pragma solidity >=0.8.18;

import {DataStructures} from "../core/libraries/DataStructures.sol";
import {SignatureLib} from "../core/libraries/SignatureLib.sol";
import {IProofCommitmentEscrow} from "../core/interfaces/IProofCommitmentEscrow.sol";

contract MockProofCommitmentEscrow is IProofCommitmentEscrow {
Expand All @@ -18,7 +18,7 @@ contract MockProofCommitmentEscrow is IProofCommitmentEscrow {
// do nothing
}

function stakeBond(DataStructures.EpochProofQuote calldata)
function stakeBond(SignatureLib.Signature calldata, uint256)
external
pure
override
Expand Down
27 changes: 15 additions & 12 deletions l1-contracts/test/Rollup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 1,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand All @@ -116,7 +115,6 @@ contract RollupTest is DecoderBase {
epochToProve: 1,
validUntilSlot: 1,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand All @@ -134,7 +132,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 1,
bondAmount: 0,
rollup: address(0),
basisPointFee: 0
});

Expand All @@ -156,7 +153,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 0,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand All @@ -176,7 +172,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 1,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand Down Expand Up @@ -212,7 +207,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 1,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand Down Expand Up @@ -248,7 +242,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 1,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand All @@ -272,7 +265,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 2 * Constants.AZTEC_EPOCH_DURATION,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand All @@ -294,7 +286,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 2 * Constants.AZTEC_EPOCH_DURATION,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand Down Expand Up @@ -322,7 +313,6 @@ contract RollupTest is DecoderBase {
epochToProve: 0,
validUntilSlot: 2 * Constants.AZTEC_EPOCH_DURATION,
bondAmount: rollup.PROOF_COMMITMENT_MIN_BOND_AMOUNT_IN_TST(),
rollup: address(0),
basisPointFee: 0
});

Expand Down Expand Up @@ -398,7 +388,7 @@ contract RollupTest is DecoderBase {
rollup.prune();
}

function testPruneDuringPropose() public setUpFor("mixed_block_1") {
function testPrune() public setUpFor("mixed_block_1") {
_testBlock("mixed_block_1", false);

assertEq(inbox.inProgress(), 3, "Invalid in progress");
Expand Down Expand Up @@ -427,12 +417,16 @@ contract RollupTest is DecoderBase {
assertNotEq(rootMixed, bytes32(0), "Invalid root");
assertNotEq(minHeightMixed, 0, "Invalid min height");

rollup.prune();
assertEq(inbox.inProgress(), 3, "Invalid in progress");
assertEq(rollup.getPendingBlockNumber(), 0, "Invalid pending block number");
assertEq(rollup.getProvenBlockNumber(), 0, "Invalid proven block number");

// @note We alter what slot is specified in the empty block!
// This means that we keep the `empty_block_1` mostly as is, but replace the slot number
// and timestamp as if it was created at a different point in time. This allow us to insert it
// as if it was the first block, even after we had originally inserted the mixed block.
// An example where this could happen would be if no-one could prove the mixed block.
// @note We prune the pending chain as part of the propose call.
_testBlock("empty_block_1", false, prunableAt);

assertEq(inbox.inProgress(), 3, "Invalid in progress");
Expand All @@ -451,6 +445,15 @@ contract RollupTest is DecoderBase {
assertNotEq(minHeightEmpty, minHeightMixed, "Invalid min height");
}

function testPruneDuringPropose() public setUpFor("mixed_block_1") {
_testBlock("mixed_block_1", false);
warpToL2Slot(Constants.AZTEC_EPOCH_DURATION * 2);
_testBlock("mixed_block_1", false, Constants.AZTEC_EPOCH_DURATION * 2);

assertEq(rollup.getPendingBlockNumber(), 1, "Invalid pending block number");
assertEq(rollup.getProvenBlockNumber(), 0, "Invalid proven block number");
}

function testBlockFee() public setUpFor("mixed_block_1") {
uint256 feeAmount = 2e18;

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_synching.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ describe('e2e_synching', () => {
const pendingBlockNumber = await rollup.read.getPendingBlockNumber();
await rollup.write.setAssumeProvenThroughBlockNumber([pendingBlockNumber - BigInt(variant.blockCount) / 2n]);

const timeliness = await rollup.read.TIMELINESS_PROVING_IN_SLOTS();
const timeliness = (await rollup.read.EPOCH_DURATION()) * 2n;
const [, , slot] = await rollup.read.blocks([(await rollup.read.getProvenBlockNumber()) + 1n]);
const timeJumpTo = await rollup.read.getTimestampForSlot([slot + timeliness]);

Expand Down

0 comments on commit 09d3064

Please sign in to comment.