From 079368a7bf27577554058e95043813a1513d13ee Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Tue, 6 Feb 2024 09:12:09 -0300 Subject: [PATCH] Add suggestions from @just-mitch on #4429 --- yarn-project/circuits.js/src/contract/contract_class.ts | 2 +- yarn-project/end-to-end/src/e2e_deploy_contract.test.ts | 4 ++++ yarn-project/foundation/src/abi/buffer.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/yarn-project/circuits.js/src/contract/contract_class.ts b/yarn-project/circuits.js/src/contract/contract_class.ts index dd32d40588c..7238802fe36 100644 --- a/yarn-project/circuits.js/src/contract/contract_class.ts +++ b/yarn-project/circuits.js/src/contract/contract_class.ts @@ -13,7 +13,7 @@ type ContractArtifactWithHash = ContractArtifact & { artifactHash: Fr }; export function getContractClassFromArtifact( artifact: ContractArtifact | ContractArtifactWithHash, ): ContractClassWithId { - const artifactHash = (artifact as ContractArtifactWithHash).artifactHash ?? computeArtifactHash(artifact); + const artifactHash = 'artifactHash' in artifact ? artifact.artifactHash : computeArtifactHash(artifact); const publicFunctions: ContractClass['publicFunctions'] = artifact.functions .filter(f => f.functionType === FunctionType.OPEN) .map(f => ({ diff --git a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts index d5e0dc3acd5..2c81ac98fc3 100644 --- a/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_deploy_contract.test.ts @@ -331,6 +331,10 @@ describe('e2e_deploy_contract', () => { // since it's common to provide all hash preimages to a function that verifies them. const artifactMetadataHash = computeArtifactMetadataHash(artifact); const unconstrainedArtifactFunctionTreeRoot = computeArtifactFunctionTreeRoot(artifact, FunctionType.OPEN); + + // We need two sibling paths because private function information is split across two trees: + // The "private function tree" captures the selectors and verification keys, and is used in the kernel circuit for verifying the proof generated by the app circuit. + // The "artifact tree" captures function bytecode and metadata, and is used by the pxe to check that its executing the code it's supposed to be executing, but it never goes into circuits. const privateFunctionTreePath = computePrivateFunctionsTree(contractClass.privateFunctions).getSiblingPath(0); const artifactFunctionTreePath = computeArtifactFunctionTree(artifact, FunctionType.SECRET)!.getSiblingPath(0); diff --git a/yarn-project/foundation/src/abi/buffer.ts b/yarn-project/foundation/src/abi/buffer.ts index b4c45af4c46..501f8070ea7 100644 --- a/yarn-project/foundation/src/abi/buffer.ts +++ b/yarn-project/foundation/src/abi/buffer.ts @@ -13,7 +13,7 @@ export function bufferAsFields(input: Buffer, targetLength: number): Fr[] { const encoded = [ new Fr(input.length), ...chunk(input, Fr.SIZE_IN_BYTES - 1).map(c => { - const fieldBytes = Buffer.alloc(32); + const fieldBytes = Buffer.alloc(Fr.SIZE_IN_BYTES); Buffer.from(c).copy(fieldBytes, 1); return Fr.fromBuffer(fieldBytes); }),