Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
alexghr committed Sep 3, 2024
1 parent 81e4feb commit ee5c9e4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { L2Block, deployL1Contract, fileURLToPath } from '@aztec/aztec.js';
import { BBCircuitVerifier } from '@aztec/bb-prover';
import { AGGREGATION_OBJECT_LENGTH, Fr, HEADER_LENGTH, Proof } from '@aztec/circuits.js';
import { Fr, Proof } from '@aztec/circuits.js';
import { type L1ContractAddresses } from '@aztec/ethereum';
import { makeTuple } from '@aztec/foundation/array';
import { type Logger } from '@aztec/foundation/log';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { AvailabilityOracleAbi, RollupAbi } from '@aztec/l1-artifacts';
import { BufferReader } from '@aztec/foundation/serialize';

import { type Anvil } from '@viem/anvil';
import { readFile } from 'fs/promises';
Expand All @@ -28,64 +26,6 @@ import { getACVMConfig } from '../fixtures/get_acvm_config.js';
import { getBBConfig } from '../fixtures/get_bb_config.js';
import { getLogger, setupL1Contracts, startAnvil } from '../fixtures/utils.js';

describe('temp', () => {
it('maps', async () => {
const blockResult = JSON.parse(
await readFile(join(fileURLToPath(import.meta.url), '../../fixtures/dumps/block_result.json'), 'utf-8'),
);

const block = L2Block.fromString(blockResult.block);
const proof = Proof.fromString(blockResult.proof);
const proverId = Fr.fromString(blockResult.proverId);
const vkTreeRoot = Fr.fromString(blockResult.vkTreeRoot);
const aggregationObject = blockResult.aggregationObject.map((x: string) => Fr.fromString(x));
const reader = BufferReader.asReader(proof.buffer.subarray(4));
const [circuitSize, numPublicInputs, publicInputsOffset] = reader.readArray(3, Fr);
console.log('reader index after header', reader.index);
const publicInputsFromProof = reader.readArray(numPublicInputs.toNumber(), Fr).map(x => x.toString());
console.log('reader index after pub inputs', reader.index);

const proofStr = `0x${Buffer.concat([
circuitSize.toBuffer(),
numPublicInputs.toBuffer(),
publicInputsOffset.toBuffer(),
reader.readToEnd(),
]).toString('hex')}` as const;

const publicInputsFromBlock = [
block.header.lastArchive.root,
block.header.globalVariables.blockNumber,
block.archive.root,
new Fr(block.archive.nextAvailableLeafIndex),
Fr.ZERO, // prev block hash
block.hash(),
...block.header.globalVariables.toFields(), // start global vars
...block.header.globalVariables.toFields(), // end global vars
new Fr(block.header.contentCommitment.outHash),
block.header.globalVariables.coinbase.toField(), // the fee taker's address
block.header.totalFees, // how much they got
...Array(62).fill(Fr.ZERO), // 31 other (fee takers, fee) pairs
vkTreeRoot,
proverId, // 0x51
...aggregationObject,
].map((x: Fr) => x.toString());

const publicInputs = proof.extractPublicInputs().map(x => x.toString());

expect(publicInputs.length).toEqual(publicInputsFromProof.length);
expect(publicInputs.slice(0, 27)).toEqual(publicInputsFromProof.slice(0, 27));
expect(publicInputs.slice(27, 89)).toEqual(publicInputsFromProof.slice(27, 89));
expect(publicInputs.slice(89, 91)).toEqual(publicInputsFromProof.slice(89, 91));
expect(publicInputs.slice(91)).toEqual(publicInputsFromProof.slice(91));

const actual = '0x' + proof.withoutPublicInputs().toString('hex');
expect(actual.length).toEqual(proofStr.length);
expect(actual).toEqual(proofStr);
expect(proof.extractAggregationObject()).toEqual(aggregationObject);
// expect(proof.extractPublicInputs()).toEqual(publicInputs);
});
});

/**
* Regenerate this test's fixture with
* AZTEC_GENERATE_TEST_DATA=1 yarn workspace @aztec/end-to-end test e2e_prover
Expand Down Expand Up @@ -215,8 +155,6 @@ describe('proof_verification', () => {
reader.readToEnd(),
]).toString('hex')}` as const;

// console.log(publicInputs);

await expect(verifierContract.read.verify([proofStr, publicInputs])).resolves.toBeTruthy();
});

Expand Down Expand Up @@ -259,40 +197,4 @@ describe('proof_verification', () => {
await expect(verifierContract.read.verify([proofStr, publicInputs])).resolves.toBeTruthy();
});
});

describe('Rollup', () => {
let availabilityContract: GetContractReturnType<typeof AvailabilityOracleAbi, typeof walletClient>;
let rollupContract: GetContractReturnType<typeof RollupAbi, typeof walletClient>;

beforeAll(async () => {
rollupContract = getContract({
address: l1ContractAddresses.rollupAddress.toString(),
abi: RollupAbi,
client: walletClient,
});

availabilityContract = getContract({
address: l1ContractAddresses.availabilityOracleAddress.toString(),
abi: AvailabilityOracleAbi,
client: walletClient,
});

await rollupContract.write.setVerifier([verifierContract.address]);
logger.info('Rollup only accepts valid proofs now');
await availabilityContract.write.publish([`0x${block.body.toBuffer().toString('hex')}`]);
});
// TODO(#6624) & TODO(#7346): Rollup.submitProof has changed to submitBlockRootProof/submitRootProof
// The inputs below may change depending on which submit fn we are using when we reinstate this test.
it('verifies proof', async () => {
const args = [
`0x${block.header.toBuffer().toString('hex')}`,
`0x${block.archive.root.toBuffer().toString('hex')}`,
`0x${proverId.toBuffer().toString('hex')}`,
`0x${serializeToBuffer(aggregationObject).toString('hex')}`,
`0x${proof.withoutPublicInputs().toString('hex')}`,
] as const;

await expect(rollupContract.write.submitBlockRootProof(args)).resolves.toBeDefined();
});
});
});
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/src/e2e_prover/e2e_prover_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export class FullProverTest {
const { walletClient, publicClient, l1ContractAddresses } = this.context.deployL1ContractsValues;

const contract = await this.circuitProofVerifier.generateSolidityContract(
'RootRollupArtifact',
'BlockRootRollupArtifact',
'UltraHonkVerifier.sol',
);

Expand Down
2 changes: 0 additions & 2 deletions yarn-project/end-to-end/src/e2e_prover/full.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ describe('full_prover', () => {
// fail the test. User asked for fixtures but we don't have any
throw new Error('No block result found in test data');
}
// TODO(#6624): Note that with honk proofs the below writes incorrect test data to file.
// The serialisation does not account for the prepended fields (circuit size, PI size, PI offset) in new Honk proofs, so the written data is shifted.
writeTestData('yarn-project/end-to-end/src/fixtures/dumps/block_result.json', JSON.stringify(blockResult));
}
},
Expand Down

0 comments on commit ee5c9e4

Please sign in to comment.