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

feat: Make public inputs the start of the UH and MH proof #12266

Merged
merged 52 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
712753e
adds new function to the transfer that allows for hashing without the…
lucasxia01 Feb 24, 2025
ec4e6b8
add test to test consume_element functionality
lucasxia01 Feb 25, 2025
e9e0dac
Merge branch 'master' into lx/transcript-allow-hashing-without-sending
lucasxia01 Feb 25, 2025
b93aee9
cleanup and change names
lucasxia01 Feb 25, 2025
78fa4ec
update oink prover and verifier to use add_to_hash_buffer
lucasxia01 Feb 25, 2025
a56d775
update oink rec verifier
lucasxia01 Feb 25, 2025
9f88bd8
update oink prover and verifier to use add_to_hash_buffer
lucasxia01 Feb 25, 2025
d7eb28d
update oink rec verifier
lucasxia01 Feb 25, 2025
4c5c057
Merge branch 'lx/public-inputs-at-proof-start' of github.com:AztecPro…
lucasxia01 Feb 26, 2025
6c1ddd0
Merge branch 'master' into lx/public-inputs-at-proof-start
lucasxia01 Feb 26, 2025
bb7b27a
fix test
lucasxia01 Feb 28, 2025
997c694
update constants for proof length
lucasxia01 Feb 28, 2025
08a3418
try to remove more issues
lucasxia01 Feb 28, 2025
d501112
fix more bugs related to using the proof to get the number of public …
lucasxia01 Feb 28, 2025
1d38474
fix mock proof creation
lucasxia01 Feb 28, 2025
c6c4818
remove client ivc public inputs offset
lucasxia01 Feb 28, 2025
6af9ec5
fix transcript serialization tests
lucasxia01 Mar 1, 2025
ab4d425
hopefully fix sol tests
lucasxia01 Mar 1, 2025
b019547
update Prover.tomls of protocol circuits
lucasxia01 Mar 1, 2025
8871399
update transcript structuring
lucasxia01 Mar 3, 2025
69789dd
add TODO
lucasxia01 Mar 3, 2025
92fa9ff
update Transcript.sol
lucasxia01 Mar 3, 2025
70e7b11
Merge remote-tracking branch 'origin/master' into lx/public-inputs-at…
lucasxia01 Mar 3, 2025
5ea2b5b
fix build
lucasxia01 Mar 3, 2025
2450abb
update the Prover.tomls of recursive protocol circuits
lucasxia01 Mar 3, 2025
0e3b766
update the contracts to do things properly
lucasxia01 Mar 3, 2025
7a91bb4
try to fix solidity, error is now a verify failure
lucasxia01 Mar 3, 2025
2c5b043
fixed client ivc test
lucasxia01 Mar 3, 2025
1b4b844
fixed UH rec verifier test
lucasxia01 Mar 3, 2025
d9f43eb
fix zk contract proof length
lucasxia01 Mar 4, 2025
0a40f16
fix verify_rollup_honk_proof
lucasxia01 Mar 4, 2025
29983e6
changed test base sol
lucasxia01 Mar 4, 2025
3be30b6
fixed challenges for solidity
lucasxia01 Mar 4, 2025
0a14531
fix sol honk zk contract
lucasxia01 Mar 4, 2025
3324da8
remove logFr statements
lucasxia01 Mar 4, 2025
e9906f1
address comments/cleanup
lucasxia01 Mar 5, 2025
ed95505
update UltraHonkBackend proof splitting
lucasxia01 Mar 5, 2025
a8beffd
Merge remote-tracking branch 'origin/master' into lx/public-inputs-at…
lucasxia01 Mar 6, 2025
842af48
delete unnecessary/harmful constructors
lucasxia01 Mar 6, 2025
40c0c06
update to backend.ts generateProof function
lucasxia01 Mar 6, 2025
bbf89fc
Merge remote-tracking branch 'origin/master' into lx/public-inputs-at…
lucasxia01 Mar 6, 2025
eec3a7c
undo a change I will have to redo later probably when my other PR get…
lucasxia01 Mar 6, 2025
e92fb0a
I'm going to have to revert this soon
lucasxia01 Mar 6, 2025
1a62e01
fix backend
lucasxia01 Mar 6, 2025
e7bd54f
fix: numPublicInputs
saleel Mar 7, 2025
9936983
Merge remote-tracking branch 'origin/master' into lx/public-inputs-at…
lucasxia01 Mar 10, 2025
06df40a
new prover tomls once again
lucasxia01 Mar 10, 2025
5c79f51
Merge branch 'lx/public-inputs-at-proof-start' of github.com:AztecPro…
lucasxia01 Mar 10, 2025
83f2ef3
Merge branch 'master' into lx/public-inputs-at-proof-start
lucasxia01 Mar 10, 2025
f79bbca
Merge branch 'master' into lx/public-inputs-at-proof-start
lucasxia01 Mar 10, 2025
cb89d02
Merge branch 'master' into lx/public-inputs-at-proof-start
saleel Mar 11, 2025
1c73c92
found the missing parsing, fixed!
lucasxia01 Mar 11, 2025
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
50 changes: 24 additions & 26 deletions barretenberg/ts/src/barretenberg/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ export class UltraPlonkBackend {
// Buffers are prepended with their size. The size takes 4 bytes.
const serializedBufferSize = 4;
const fieldByteSize = 32;
const publicInputOffset = 3;
const publicInputsOffsetBytes = publicInputOffset * fieldByteSize;

/**
* Options for the UltraHonkBackend.
Expand Down Expand Up @@ -218,19 +216,18 @@ export class UltraHonkBackend {
const numPublicInputs = Number(proofAsStrings[1]);

// Account for the serialized buffer size at start
const publicInputsOffset = publicInputsOffsetBytes + serializedBufferSize;
// Get the part before and after the public inputs
const proofStart = proofWithPublicInputs.slice(0, publicInputsOffset);
const proofStart = proofWithPublicInputs.slice(0, serializedBufferSize);
const publicInputsSplitIndex = numPublicInputs * fieldByteSize;
const proofEnd = proofWithPublicInputs.slice(publicInputsOffset + publicInputsSplitIndex);
const proofEnd = proofWithPublicInputs.slice(serializedBufferSize + publicInputsSplitIndex);

// Construct the proof without the public inputs
const proof = new Uint8Array([...proofStart, ...proofEnd]);

// Fetch the number of public inputs out of the proof string
const publicInputsConcatenated = proofWithPublicInputs.slice(
publicInputsOffset,
publicInputsOffset + publicInputsSplitIndex,
serializedBufferSize,
serializedBufferSize + publicInputsSplitIndex,
);
const publicInputs = deflattenFields(publicInputsConcatenated);

Expand All @@ -253,39 +250,40 @@ export class UltraHonkBackend {
gunzip(compressedWitness),
);

// Write VK to get the VK
Copy link
Contributor Author

Choose a reason for hiding this comment

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

extra call is not ideal since its more work just to fetch the number of public inputs. The vk or maybe just the number of public inputs should be returned by proof generation perhaps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the bb.js interface just needs to be reworked similarly to the bb interface so that prove can output both a proof and a vk...

const writeVKUltraHonk = options?.keccak
? this.api.acirProveUltraKeccakHonk.bind(this.api)
: this.api.acirProveUltraHonk.bind(this.api);

const vk = await writeVKUltraHonk(
this.acirUncompressedBytecode,
this.circuitOptions.recursive,
gunzip(compressedWitness),
);

// proofWithPublicInputs starts with a four-byte size
const numSerdeHeaderBytes = 4;
// some public inputs are handled specially
const numKZGAccumulatorFieldElements = 16;
// proof begins with: size, num public inputs, public input offset
const numProofPreambleElements = 3;
const publicInputsSizeIndex = 1;
const publicInputsSizeIndex = 1; // index into VK for numPublicInputs

// Slice serde header and convert to fields
const proofAsStrings = deflattenFields(proofWithPublicInputs.slice(numSerdeHeaderBytes));
const numPublicInputs = Number(proofAsStrings[publicInputsSizeIndex]) - numKZGAccumulatorFieldElements;

// Account for the serialized buffer size at start
const publicInputsOffset = publicInputsOffsetBytes + serializedBufferSize;
const publicInputsSplitIndex = numPublicInputs * fieldByteSize;
const vkAsStrings = deflattenFields(vk.slice(numSerdeHeaderBytes));
const numPublicInputs = Number(vkAsStrings[publicInputsSizeIndex]) - numKZGAccumulatorFieldElements;

// Construct the proof without the public inputs
const numPublicInputsBytes = numPublicInputs * fieldByteSize;
const numHeaderPlusPreambleBytes = numSerdeHeaderBytes + numProofPreambleElements * fieldByteSize;
const proofNoPIs = new Uint8Array(proofWithPublicInputs.length - numPublicInputsBytes);
// copy the elements before the public inputs
proofNoPIs.set(proofWithPublicInputs.subarray(0, numHeaderPlusPreambleBytes), 0);
proofNoPIs.set(proofWithPublicInputs.subarray(0, numSerdeHeaderBytes), 0);
// copy the elements after the public inputs
proofNoPIs.set(
proofWithPublicInputs.subarray(numHeaderPlusPreambleBytes + numPublicInputsBytes),
numHeaderPlusPreambleBytes,
);
proofNoPIs.set(proofWithPublicInputs.subarray(numSerdeHeaderBytes + numPublicInputsBytes), numSerdeHeaderBytes);
const proof: string[] = deflattenFields(proofNoPIs.slice(numSerdeHeaderBytes));

// Fetch the number of public inputs out of the proof string
const publicInputsConcatenated = proofWithPublicInputs.slice(
publicInputsOffset,
publicInputsOffset + publicInputsSplitIndex,
serializedBufferSize,
serializedBufferSize + numPublicInputsBytes,
);
const publicInputs = deflattenFields(publicInputsConcatenated);

Expand Down Expand Up @@ -386,8 +384,8 @@ export class AztecClientBackend {
await this.instantiate();
const proofAndVk = await this.api.acirProveAztecClient(this.acirMsgpack, witnessMsgpack);
const [proof, vk] = proofAndVk;
if (!await this.verify(proof, vk)) {
throw new AztecClientBackendError("Failed to verify the private (ClientIVC) transaction proof!");
if (!(await this.verify(proof, vk))) {
throw new AztecClientBackendError('Failed to verify the private (ClientIVC) transaction proof!');
}
return proofAndVk;
}
Expand Down
22 changes: 9 additions & 13 deletions barretenberg/ts/src/proof/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,21 @@ export type ProofDataForRecursion = {
// Buffers are prepended with their size. The size takes 4 bytes.
const serializedBufferSize = 4;
const fieldByteSize = 32;
const publicInputOffset = 3;
const publicInputsOffsetBytes = publicInputOffset * fieldByteSize;

export function splitHonkProof(proofWithPublicInputs: Uint8Array): { publicInputs: Uint8Array; proof: Uint8Array } {
const proofAsStrings = deflattenFields(proofWithPublicInputs.slice(4));

const numPublicInputs = Number(proofAsStrings[1]);

export function splitHonkProof(
proofWithPublicInputs: Uint8Array,
numPublicInputs: number,
): { publicInputs: Uint8Array; proof: Uint8Array } {
// Account for the serialized buffer size at start
const publicInputsOffset = publicInputsOffsetBytes + serializedBufferSize;
// Get the part before and after the public inputs
const proofStart = proofWithPublicInputs.slice(0, publicInputsOffset);
const proofStart = proofWithPublicInputs.slice(0, serializedBufferSize);
const publicInputsSplitIndex = numPublicInputs * fieldByteSize;
const proofEnd = proofWithPublicInputs.slice(publicInputsOffset + publicInputsSplitIndex);
const proofEnd = proofWithPublicInputs.slice(serializedBufferSize + publicInputsSplitIndex);
// Construct the proof without the public inputs
const proof = new Uint8Array([...proofStart, ...proofEnd]);

// Fetch the number of public inputs out of the proof string
const publicInputs = proofWithPublicInputs.slice(publicInputsOffset, publicInputsOffset + publicInputsSplitIndex);
const publicInputs = proofWithPublicInputs.slice(serializedBufferSize, serializedBufferSize + publicInputsSplitIndex);

return {
proof,
Expand All @@ -50,8 +46,8 @@ export function splitHonkProof(proofWithPublicInputs: Uint8Array): { publicInput
}

export function reconstructHonkProof(publicInputs: Uint8Array, proof: Uint8Array): Uint8Array {
const proofStart = proof.slice(0, publicInputsOffsetBytes + serializedBufferSize);
const proofEnd = proof.slice(publicInputsOffsetBytes + serializedBufferSize);
const proofStart = proof.slice(0, serializedBufferSize);
const proofEnd = proof.slice(serializedBufferSize);

// Concatenate publicInputs and proof
const proofWithPublicInputs = Uint8Array.from([...proofStart, ...publicInputs, ...proofEnd]);
Expand Down
Loading