@@ -11,7 +11,7 @@ import { AZTEC_EPOCH_DURATION, AZTEC_SLOT_DURATION, type AztecAddress, EthAddres
1111import { Buffer32 } from '@aztec/foundation/buffer' ;
1212import { times } from '@aztec/foundation/collection' ;
1313import { Secp256k1Signer , keccak256 , randomBigInt , randomInt } from '@aztec/foundation/crypto' ;
14- import { RollupAbi } from '@aztec/l1-artifacts' ;
14+ import { ProofCommitmentEscrowAbi , RollupAbi , TestERC20Abi } from '@aztec/l1-artifacts' ;
1515import { StatefulTestContract } from '@aztec/noir-contracts.js' ;
1616
1717import { 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
2933import {
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