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

fix: make bytecode part of artifact hash preimage again #9771

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions yarn-project/circuits.js/src/contract/artifact_hash.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('ArtifactHash', () => {

for (let i = 0; i < 1000; i++) {
expect(computeArtifactHash(testArtifact).toString()).toMatchInlineSnapshot(
`"0x237feccc8e34a39c0e5133c8653fc278b39275bfa3f7459e4aba07d53b752c19"`,
`"0x21070d88558fdc3906322f267cf6f0f632caf3949295520fe1f71f156fbb0d0b"`,
);
}
});
Expand All @@ -43,7 +43,7 @@ describe('ArtifactHash', () => {
const testArtifact = loadContractArtifact(content);

expect(computeArtifactHash(testArtifact).toString()).toMatchInlineSnapshot(
`"0x237feccc8e34a39c0e5133c8653fc278b39275bfa3f7459e4aba07d53b752c19"`,
`"0x21070d88558fdc3906322f267cf6f0f632caf3949295520fe1f71f156fbb0d0b"`,
);
});
});
9 changes: 4 additions & 5 deletions yarn-project/circuits.js/src/contract/artifact_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@ export function computeFunctionArtifactHash(
| (Pick<FunctionArtifact, 'bytecode'> & { functionMetadataHash: Fr; selector: FunctionSelector }),
) {
const selector = 'selector' in fn ? fn.selector : FunctionSelector.fromNameAndParameters(fn);
// TODO(#5860): make bytecode part of artifact hash preimage again
// const bytecodeHash = sha256Fr(fn.bytecode).toBuffer();
// const metadataHash = 'functionMetadataHash' in fn ? fn.functionMetadataHash : computeFunctionMetadataHash(fn);
// return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer(), metadataHash.toBuffer(), bytecodeHash]));
return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer()]));

const bytecodeHash = sha256Fr(fn.bytecode).toBuffer();
const metadataHash = 'functionMetadataHash' in fn ? fn.functionMetadataHash : computeFunctionMetadataHash(fn);
return sha256Fr(Buffer.concat([numToUInt8(VERSION), selector.toBuffer(), metadataHash.toBuffer(), bytecodeHash]));
}

export function computeFunctionMetadataHash(fn: FunctionArtifact) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ describe('private_function_membership_proof', () => {
expect(isValidPrivateFunctionMembershipProof(fn, contractClass)).toBeTruthy();
});

// TODO(#5860): Re-enable this test once noir non-determinism is addressed
test.skip.each([
test.each([
'artifactTreeSiblingPath',
'artifactMetadataHash',
'functionMetadataHash',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ describe('unconstrained_function_membership_proof', () => {
expect(isValidUnconstrainedFunctionMembershipProof(fn, contractClass)).toBeTruthy();
});

// TODO(#5860): Re-enable this test once noir non-determinism is addressed
test.skip.each(['artifactTreeSiblingPath', 'artifactMetadataHash', 'functionMetadataHash'] as const)(
test.each(['artifactTreeSiblingPath', 'artifactMetadataHash', 'functionMetadataHash'] as const)(
'fails proof if %s is mangled',
field => {
const proof = createUnconstrainedFunctionMembershipProof(selector, artifact);
Expand Down
5 changes: 1 addition & 4 deletions yarn-project/pxe/src/pxe_service/pxe_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ export class PXEService implements PXE {
`Artifact does not match expected class id (computed ${contractClassId} but instance refers to ${instance.contractClassId})`,
);
}
if (
// Computed address from the instance does not match address inside instance
!computeContractAddressFromInstance(instance).equals(instance.address)
) {
if (!computeContractAddressFromInstance(instance).equals(instance.address)) {
throw new Error('Added a contract in which the address does not match the contract instance.');
}

Expand Down