|
1 | 1 | import { BatchedBlob } from '@aztec/blob-lib'; |
2 | 2 | import type { L1TxUtils, RollupContract } from '@aztec/ethereum'; |
3 | 3 | import { SecretValue } from '@aztec/foundation/config'; |
| 4 | +import { randomBytes } from '@aztec/foundation/crypto'; |
4 | 5 | import { EthAddress } from '@aztec/foundation/eth-address'; |
5 | 6 | import { Fr } from '@aztec/foundation/fields'; |
6 | 7 | import type { PublisherConfig, TxSenderConfig } from '@aztec/sequencer-client'; |
7 | 8 | import { Proof } from '@aztec/stdlib/proofs'; |
8 | 9 | import { RootRollupPublicInputs } from '@aztec/stdlib/rollup'; |
9 | 10 |
|
| 11 | +import { jest } from '@jest/globals'; |
10 | 12 | import { type MockProxy, mock } from 'jest-mock-extended'; |
11 | 13 |
|
12 | 14 | import { ProverNodePublisher } from './prover-node-publisher.js'; |
@@ -193,4 +195,87 @@ describe('prover-node-publisher', () => { |
193 | 195 | } |
194 | 196 | }, |
195 | 197 | ); |
| 198 | + |
| 199 | + it('handles reverted txs correctly', async () => { |
| 200 | + const blocks = [RootRollupPublicInputs.random(), RootRollupPublicInputs.random()]; |
| 201 | + |
| 202 | + // Return the tips specified by the test |
| 203 | + rollup.getTips.mockResolvedValue({ |
| 204 | + pendingBlockNumber: 2n, |
| 205 | + provenBlockNumber: 1n, |
| 206 | + }); |
| 207 | + |
| 208 | + // Return the requested block |
| 209 | + rollup.getBlock.mockImplementation((i: bigint) => |
| 210 | + Promise.resolve({ |
| 211 | + archive: blocks[Number(i) - 1].endArchiveRoot.toString(), |
| 212 | + attestationsHash: '0x', // unused, |
| 213 | + payloadDigest: '0x', // unused, |
| 214 | + headerHash: '0x', // unused, |
| 215 | + blobCommitmentsHash: '0x', // unused, |
| 216 | + slotNumber: 0n, // unused, |
| 217 | + feeHeader: { |
| 218 | + excessMana: 0n, // unused |
| 219 | + manaUsed: 0n, // unused |
| 220 | + feeAssetPriceNumerator: 0n, // unused |
| 221 | + congestionCost: 0n, // unused |
| 222 | + proverCost: 0n, // unused |
| 223 | + }, |
| 224 | + }), |
| 225 | + ); |
| 226 | + |
| 227 | + // We have built a rollup proof of the range fromBlock - toBlock |
| 228 | + // so we need to set our archives and hashes accordingly |
| 229 | + const ourPublicInputs = RootRollupPublicInputs.random(); |
| 230 | + ourPublicInputs.previousArchiveRoot = blocks[0].endArchiveRoot ?? Fr.ZERO; |
| 231 | + ourPublicInputs.endArchiveRoot = blocks[1].endArchiveRoot ?? Fr.ZERO; |
| 232 | + |
| 233 | + const ourBatchedBlob = new BatchedBlob( |
| 234 | + ourPublicInputs.blobPublicInputs.blobCommitmentsHash, |
| 235 | + ourPublicInputs.blobPublicInputs.z, |
| 236 | + ourPublicInputs.blobPublicInputs.y, |
| 237 | + ourPublicInputs.blobPublicInputs.c, |
| 238 | + ourPublicInputs.blobPublicInputs.c.negate(), // Fill with dummy value |
| 239 | + ); |
| 240 | + |
| 241 | + // Return our public inputs |
| 242 | + const totalFields = ourPublicInputs.toFields(); |
| 243 | + rollup.getEpochProofPublicInputs.mockResolvedValue(totalFields.map(x => x.toString())); |
| 244 | + |
| 245 | + jest.spyOn(l1Utils, 'getSenderBalance').mockResolvedValue(42n); |
| 246 | + jest.spyOn(l1Utils, 'getSenderAddress').mockReturnValue(EthAddress.random()); |
| 247 | + |
| 248 | + jest.spyOn(l1Utils, 'sendAndMonitorTransaction').mockResolvedValue({ |
| 249 | + gasPrice: {} as any, |
| 250 | + receipt: { |
| 251 | + status: 'reverted', |
| 252 | + effectiveGasPrice: 1n, |
| 253 | + gasUsed: 1n, |
| 254 | + transactionHash: `0x${randomBytes(32).toString('hex')}`, |
| 255 | + cumulativeGasUsed: 1n, |
| 256 | + blockNumber: 42n, |
| 257 | + blockHash: `0x${randomBytes(32).toString('hex')}`, |
| 258 | + from: EthAddress.random().toString(), |
| 259 | + } as any, |
| 260 | + }); |
| 261 | + |
| 262 | + jest.spyOn(l1Utils, 'getTransactionStats').mockResolvedValue({ |
| 263 | + calldataGas: 1, |
| 264 | + calldataSize: 1, |
| 265 | + sender: EthAddress.random().toString(), |
| 266 | + transactionHash: `0x${randomBytes(32).toString('hex')}`, |
| 267 | + }); |
| 268 | + |
| 269 | + const result = await publisher.submitEpochProof({ |
| 270 | + epochNumber: 2, |
| 271 | + fromBlock: 2, |
| 272 | + toBlock: 2, |
| 273 | + publicInputs: ourPublicInputs, |
| 274 | + proof: Proof.empty(), |
| 275 | + batchedBlobInputs: ourBatchedBlob, |
| 276 | + attestations: [], |
| 277 | + }); |
| 278 | + |
| 279 | + expect(result).toBe(false); |
| 280 | + }); |
196 | 281 | }); |
0 commit comments