Skip to content

Commit 3a1a62c

Browse files
authored
chore: fix and re-enable prover coordination e2e test (#9344)
1 parent 47718ea commit 3a1a62c

File tree

4 files changed

+97
-16
lines changed

4 files changed

+97
-16
lines changed

l1-contracts/src/core/libraries/TimeMath.sol

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ function addEpoch(Epoch a, Epoch b) pure returns (Epoch) {
131131
return Epoch.wrap(Epoch.unwrap(a) + Epoch.unwrap(b));
132132
}
133133

134+
function gteEpoch(Epoch a, Epoch b) pure returns (bool) {
135+
return Epoch.unwrap(a) >= Epoch.unwrap(b);
136+
}
137+
138+
function gtEpoch(Epoch a, Epoch b) pure returns (bool) {
139+
return Epoch.unwrap(a) > Epoch.unwrap(b);
140+
}
141+
142+
function lteEpoch(Epoch a, Epoch b) pure returns (bool) {
143+
return Epoch.unwrap(a) <= Epoch.unwrap(b);
144+
}
145+
146+
function ltEpoch(Epoch a, Epoch b) pure returns (bool) {
147+
return Epoch.unwrap(a) < Epoch.unwrap(b);
148+
}
149+
134150
using {
135151
addTimestamp as +,
136152
subTimestamp as -,
@@ -142,7 +158,16 @@ using {
142158
eqTimestamp as ==
143159
} for Timestamp global;
144160

145-
using {addEpoch as +, subEpoch as -, eqEpoch as ==, neqEpoch as !=} for Epoch global;
161+
using {
162+
addEpoch as +,
163+
subEpoch as -,
164+
eqEpoch as ==,
165+
neqEpoch as !=,
166+
gteEpoch as >=,
167+
gtEpoch as >,
168+
lteEpoch as <=,
169+
ltEpoch as <
170+
} for Epoch global;
146171

147172
using {
148173
eqSlot as ==,

scripts/ci/get_e2e_jobs.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ allow_list=(
2525
"integration-l1-publisher"
2626
"e2e-cheat-codes"
2727
"e2e-prover-fake-proofs"
28+
"e2e-prover-coordination"
2829
"e2e-lending-contract"
2930
"kind-network-smoke"
3031
)

yarn-project/end-to-end/Earthfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ e2e-prover-fake-proofs:
2929
LOCALLY
3030
RUN FAKE_PROOFS=1 ./scripts/e2e_test.sh ./src/e2e_prover/full
3131

32+
e2e-prover-coordination:
33+
LOCALLY
34+
RUN ./scripts/e2e_test.sh ./src/prover-coordination
35+
3236
e2e-account-contracts:
3337
LOCALLY
3438
RUN ./scripts/e2e_test.sh ./src/e2e_account_contracts.test.ts

yarn-project/end-to-end/src/prover-coordination/e2e_prover_coordination.test.ts

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AZTEC_EPOCH_DURATION, AZTEC_SLOT_DURATION, type AztecAddress, EthAddres
1111
import { Buffer32 } from '@aztec/foundation/buffer';
1212
import { times } from '@aztec/foundation/collection';
1313
import { Secp256k1Signer, keccak256, randomBigInt, randomInt } from '@aztec/foundation/crypto';
14-
import { RollupAbi } from '@aztec/l1-artifacts';
14+
import { ProofCommitmentEscrowAbi, RollupAbi, TestERC20Abi } from '@aztec/l1-artifacts';
1515
import { StatefulTestContract } from '@aztec/noir-contracts.js';
1616

1717
import { beforeAll } from '@jest/globals';
@@ -22,9 +22,13 @@ import {
2222
type HttpTransport,
2323
type PublicClient,
2424
type WalletClient,
25+
createWalletClient,
2526
getAddress,
2627
getContract,
28+
http,
2729
} from 'viem';
30+
import { privateKeyToAccount } from 'viem/accounts';
31+
import { foundry } from 'viem/chains';
2832

2933
import {
3034
type ISnapshotManager,
@@ -42,6 +46,14 @@ describe('e2e_prover_coordination', () => {
4246
let publicClient: PublicClient;
4347
let cc: EthCheatCodes;
4448
let publisherAddress: EthAddress;
49+
let feeJuiceContract: GetContractReturnType<typeof TestERC20Abi, WalletClient<HttpTransport, Chain, Account>>;
50+
let escrowContract: GetContractReturnType<
51+
typeof ProofCommitmentEscrowAbi,
52+
WalletClient<HttpTransport, Chain, Account>
53+
>;
54+
55+
let proverSigner: Secp256k1Signer;
56+
let proverWallet: WalletClient<HttpTransport, Chain, Account>;
4557

4658
let logger: DebugLogger;
4759
let snapshotManager: ISnapshotManager;
@@ -78,6 +90,7 @@ describe('e2e_prover_coordination', () => {
7890

7991
ctx = await snapshotManager.setup();
8092

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

8396
cc = new EthCheatCodes(ctx.aztecNodeConfig.l1RpcUrl);
@@ -89,6 +102,27 @@ describe('e2e_prover_coordination', () => {
89102
abi: RollupAbi,
90103
client: ctx.deployL1ContractsValues.walletClient,
91104
});
105+
feeJuiceContract = getContract({
106+
address: getAddress(ctx.deployL1ContractsValues.l1ContractAddresses.feeJuiceAddress.toString()),
107+
abi: TestERC20Abi,
108+
client: ctx.deployL1ContractsValues.walletClient,
109+
});
110+
111+
// Create a prover wallet
112+
const proverKey = Buffer32.random();
113+
proverSigner = new Secp256k1Signer(proverKey);
114+
proverWallet = createWalletClient({
115+
account: privateKeyToAccount(proverKey.to0xString()),
116+
chain: foundry,
117+
transport: http(ctx.aztecNodeConfig.l1RpcUrl),
118+
});
119+
120+
const escrowAddress = await rollupContract.read.PROOF_COMMITMENT_ESCROW();
121+
escrowContract = getContract({
122+
address: getAddress(escrowAddress.toString()),
123+
abi: ProofCommitmentEscrowAbi,
124+
client: ctx.deployL1ContractsValues.walletClient,
125+
});
92126
});
93127

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

143+
const performEscrow = async (amount: bigint) => {
144+
// Fund with ether
145+
await cc.setBalance(proverSigner.address, 10_000n * 10n ** 18n);
146+
// Fund with fee juice
147+
await feeJuiceContract.write.mint([proverWallet.account.address, amount]);
148+
149+
// Approve the escrow contract to spend our funds
150+
await feeJuiceContract.write.approve([escrowContract.address, amount], {
151+
account: proverWallet.account,
152+
});
153+
154+
// Deposit the funds into the escrow contract
155+
await escrowContract.write.deposit([amount], {
156+
account: proverWallet.account,
157+
});
158+
};
159+
109160
const getL1Timestamp = async () => {
110161
return BigInt((await publicClient.getBlock()).timestamp);
111162
};
@@ -157,14 +208,12 @@ describe('e2e_prover_coordination', () => {
157208
epochToProve,
158209
validUntilSlot,
159210
bondAmount,
160-
prover,
161211
basisPointFee,
162212
signer,
163213
}: {
164214
epochToProve: bigint;
165215
validUntilSlot?: bigint;
166216
bondAmount?: bigint;
167-
prover?: EthAddress;
168217
basisPointFee?: number;
169218
signer?: Secp256k1Signer;
170219
}) => {
@@ -173,23 +222,28 @@ describe('e2e_prover_coordination', () => {
173222
epochToProve,
174223
validUntilSlot ?? randomBigInt(10000n),
175224
bondAmount ?? randomBigInt(10000n) + 1000n,
176-
prover ?? EthAddress.fromString('0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'),
225+
signer.address,
177226
basisPointFee ?? randomInt(100),
178227
);
179228
const digest = await rollupContract.read.quoteToDigest([quotePayload.toViemArgs()]);
229+
180230
return EpochProofQuote.new(Buffer32.fromString(digest), quotePayload, signer);
181231
};
182232

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

187-
// Here we are creating a proof quote for epoch 0, this will NOT get used yet
237+
// Ensure the prover has enough funds to in escrow
238+
await performEscrow(10000000n);
239+
240+
// Here we are creating a proof quote for epoch 0
188241
const quoteForEpoch0 = await makeEpochProofQuote({
189242
epochToProve: 0n,
190243
validUntilSlot: BigInt(AZTEC_EPOCH_DURATION + 10),
191244
bondAmount: 10000n,
192245
basisPointFee: 1,
246+
signer: proverSigner,
193247
});
194248

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

203257
const epoch0BlockNumber = await getPendingBlockNumber();
204258

205-
// Verify that the claim state on L1 is unitialised
206-
// The rollup contract should have an uninitialised proof claim struct
207-
await expectProofClaimOnL1({
208-
epochToProve: 0n,
209-
basisPointFee: 0,
210-
bondAmount: 0n,
211-
prover: EthAddress.ZERO,
212-
proposer: EthAddress.ZERO,
213-
});
259+
// Verify that we can claim the current epoch
260+
await expectProofClaimOnL1({ ...quoteForEpoch0.payload, proposer: publisherAddress });
214261

215262
// Now go to epoch 1
216263
await advanceToNextEpoch();
@@ -243,6 +290,7 @@ describe('e2e_prover_coordination', () => {
243290
validUntilSlot: currentSlot + 2n,
244291
bondAmount: 10000n,
245292
basisPointFee: 10 + i,
293+
signer: proverSigner,
246294
}),
247295
),
248296
);
@@ -252,20 +300,23 @@ describe('e2e_prover_coordination', () => {
252300
validUntilSlot: 3n,
253301
bondAmount: 10000n,
254302
basisPointFee: 1,
303+
signer: proverSigner,
255304
});
256305

257306
const proofQuoteInvalidEpoch = await makeEpochProofQuote({
258-
epochToProve: 2n,
307+
epochToProve: 4n,
259308
validUntilSlot: currentSlot + 4n,
260309
bondAmount: 10000n,
261310
basisPointFee: 2,
311+
signer: proverSigner,
262312
});
263313

264314
const proofQuoteInsufficientBond = await makeEpochProofQuote({
265315
epochToProve: 1n,
266316
validUntilSlot: currentSlot + 4n,
267317
bondAmount: 0n,
268318
basisPointFee: 3,
319+
signer: proverSigner,
269320
});
270321

271322
const allQuotes = [proofQuoteInvalidSlot, proofQuoteInvalidEpoch, ...validQuotes, proofQuoteInsufficientBond];

0 commit comments

Comments
 (0)