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

chore: fix and re-enable prover coordination e2e test #9344

Merged
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
27 changes: 26 additions & 1 deletion l1-contracts/src/core/libraries/TimeMath.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,22 @@ function addEpoch(Epoch a, Epoch b) pure returns (Epoch) {
return Epoch.wrap(Epoch.unwrap(a) + Epoch.unwrap(b));
}

function gteEpoch(Epoch a, Epoch b) pure returns (bool) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was added for something i reverted, but i think ill keep it anyway

return Epoch.unwrap(a) >= Epoch.unwrap(b);
}

function gtEpoch(Epoch a, Epoch b) pure returns (bool) {
return Epoch.unwrap(a) > Epoch.unwrap(b);
}

function lteEpoch(Epoch a, Epoch b) pure returns (bool) {
return Epoch.unwrap(a) <= Epoch.unwrap(b);
}

function ltEpoch(Epoch a, Epoch b) pure returns (bool) {
return Epoch.unwrap(a) < Epoch.unwrap(b);
}

using {
addTimestamp as +,
subTimestamp as -,
Expand All @@ -142,7 +158,16 @@ using {
eqTimestamp as ==
} for Timestamp global;

using {addEpoch as +, subEpoch as -, eqEpoch as ==, neqEpoch as !=} for Epoch global;
using {
addEpoch as +,
subEpoch as -,
eqEpoch as ==,
neqEpoch as !=,
gteEpoch as >=,
gtEpoch as >,
lteEpoch as <=,
ltEpoch as <
} for Epoch global;

using {
eqSlot as ==,
Expand Down
1 change: 1 addition & 0 deletions scripts/ci/get_e2e_jobs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ allow_list=(
"integration-l1-publisher"
"e2e-cheat-codes"
"e2e-prover-fake-proofs"
"e2e-prover-coordination"
"e2e-lending-contract"
"kind-network-smoke"
)
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/end-to-end/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ e2e-prover-fake-proofs:
LOCALLY
RUN FAKE_PROOFS=1 ./scripts/e2e_test.sh ./src/e2e_prover/full

e2e-prover-coordination:
LOCALLY
RUN ./scripts/e2e_test.sh ./src/prover-coordination

e2e-account-contracts:
LOCALLY
RUN ./scripts/e2e_test.sh ./src/e2e_account_contracts.test.ts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { AZTEC_EPOCH_DURATION, AZTEC_SLOT_DURATION, type AztecAddress, EthAddres
import { Buffer32 } from '@aztec/foundation/buffer';
import { times } from '@aztec/foundation/collection';
import { Secp256k1Signer, keccak256, randomBigInt, randomInt } from '@aztec/foundation/crypto';
import { RollupAbi } from '@aztec/l1-artifacts';
import { ProofCommitmentEscrowAbi, RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts';
import { StatefulTestContract } from '@aztec/noir-contracts.js';

import { beforeAll } from '@jest/globals';
Expand All @@ -22,9 +22,13 @@ import {
type HttpTransport,
type PublicClient,
type WalletClient,
createWalletClient,
getAddress,
getContract,
http,
} from 'viem';
import { privateKeyToAccount } from 'viem/accounts';
import { foundry } from 'viem/chains';

import {
type ISnapshotManager,
Expand All @@ -42,6 +46,14 @@ describe('e2e_prover_coordination', () => {
let publicClient: PublicClient;
let cc: EthCheatCodes;
let publisherAddress: EthAddress;
let feeJuiceContract: GetContractReturnType<typeof TestERC20Abi, WalletClient<HttpTransport, Chain, Account>>;
let escrowContract: GetContractReturnType<
typeof ProofCommitmentEscrowAbi,
WalletClient<HttpTransport, Chain, Account>
>;

let proverSigner: Secp256k1Signer;
let proverWallet: WalletClient<HttpTransport, Chain, Account>;

let logger: DebugLogger;
let snapshotManager: ISnapshotManager;
Expand Down Expand Up @@ -78,6 +90,7 @@ describe('e2e_prover_coordination', () => {

ctx = await snapshotManager.setup();

// Don't run the prover node work loop - we manually control within this test
await ctx.proverNode!.stop();

cc = new EthCheatCodes(ctx.aztecNodeConfig.l1RpcUrl);
Expand All @@ -89,6 +102,27 @@ describe('e2e_prover_coordination', () => {
abi: RollupAbi,
client: ctx.deployL1ContractsValues.walletClient,
});
feeJuiceContract = getContract({
address: getAddress(ctx.deployL1ContractsValues.l1ContractAddresses.feeJuiceAddress.toString()),
abi: TestERC20Abi,
client: ctx.deployL1ContractsValues.walletClient,
});

// Create a prover wallet
const proverKey = Buffer32.random();
proverSigner = new Secp256k1Signer(proverKey);
proverWallet = createWalletClient({
account: privateKeyToAccount(proverKey.to0xString()),
chain: foundry,
transport: http(ctx.aztecNodeConfig.l1RpcUrl),
});

const escrowAddress = await rollupContract.read.PROOF_COMMITMENT_ESCROW();
escrowContract = getContract({
address: getAddress(escrowAddress.toString()),
abi: ProofCommitmentEscrowAbi,
client: ctx.deployL1ContractsValues.walletClient,
});
});

const expectProofClaimOnL1 = async (expected: {
Expand All @@ -106,6 +140,23 @@ describe('e2e_prover_coordination', () => {
expect(proposer).toEqual(expected.proposer.toChecksumString());
};

const performEscrow = async (amount: bigint) => {
// Fund with ether
await cc.setBalance(proverSigner.address, 10_000n * 10n ** 18n);
// Fund with fee juice
await feeJuiceContract.write.mint([proverWallet.account.address, amount]);

// Approve the escrow contract to spend our funds
await feeJuiceContract.write.approve([escrowContract.address, amount], {
account: proverWallet.account,
});

// Deposit the funds into the escrow contract
await escrowContract.write.deposit([amount], {
account: proverWallet.account,
});
};

const getL1Timestamp = async () => {
return BigInt((await publicClient.getBlock()).timestamp);
};
Expand Down Expand Up @@ -157,14 +208,12 @@ describe('e2e_prover_coordination', () => {
epochToProve,
validUntilSlot,
bondAmount,
prover,
basisPointFee,
signer,
}: {
epochToProve: bigint;
validUntilSlot?: bigint;
bondAmount?: bigint;
prover?: EthAddress;
basisPointFee?: number;
signer?: Secp256k1Signer;
}) => {
Expand All @@ -173,23 +222,28 @@ describe('e2e_prover_coordination', () => {
epochToProve,
validUntilSlot ?? randomBigInt(10000n),
bondAmount ?? randomBigInt(10000n) + 1000n,
prover ?? EthAddress.fromString('0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'),
signer.address,
basisPointFee ?? randomInt(100),
);
const digest = await rollupContract.read.quoteToDigest([quotePayload.toViemArgs()]);

return EpochProofQuote.new(Buffer32.fromString(digest), quotePayload, signer);
};

it('Sequencer selects best valid proving quote for each block', async () => {
// We want to create a set of proving quotes, some valid and some invalid
// The sequencer should select the cheapest valid quote when it proposes the block

// Here we are creating a proof quote for epoch 0, this will NOT get used yet
// Ensure the prover has enough funds to in escrow
await performEscrow(10000000n);

// Here we are creating a proof quote for epoch 0
const quoteForEpoch0 = await makeEpochProofQuote({
epochToProve: 0n,
validUntilSlot: BigInt(AZTEC_EPOCH_DURATION + 10),
bondAmount: 10000n,
basisPointFee: 1,
signer: proverSigner,
});

// Send in the quote
Expand All @@ -202,15 +256,8 @@ describe('e2e_prover_coordination', () => {

const epoch0BlockNumber = await getPendingBlockNumber();

// Verify that the claim state on L1 is unitialised
// The rollup contract should have an uninitialised proof claim struct
await expectProofClaimOnL1({
epochToProve: 0n,
basisPointFee: 0,
bondAmount: 0n,
prover: EthAddress.ZERO,
proposer: EthAddress.ZERO,
});
// Verify that we can claim the current epoch
await expectProofClaimOnL1({ ...quoteForEpoch0.payload, proposer: publisherAddress });

// Now go to epoch 1
await advanceToNextEpoch();
Expand Down Expand Up @@ -243,6 +290,7 @@ describe('e2e_prover_coordination', () => {
validUntilSlot: currentSlot + 2n,
bondAmount: 10000n,
basisPointFee: 10 + i,
signer: proverSigner,
}),
),
);
Expand All @@ -252,20 +300,23 @@ describe('e2e_prover_coordination', () => {
validUntilSlot: 3n,
bondAmount: 10000n,
basisPointFee: 1,
signer: proverSigner,
});

const proofQuoteInvalidEpoch = await makeEpochProofQuote({
epochToProve: 2n,
epochToProve: 4n,
validUntilSlot: currentSlot + 4n,
bondAmount: 10000n,
basisPointFee: 2,
signer: proverSigner,
});

const proofQuoteInsufficientBond = await makeEpochProofQuote({
epochToProve: 1n,
validUntilSlot: currentSlot + 4n,
bondAmount: 0n,
basisPointFee: 3,
signer: proverSigner,
});

const allQuotes = [proofQuoteInvalidSlot, proofQuoteInvalidEpoch, ...validQuotes, proofQuoteInsufficientBond];
Expand Down
Loading