diff --git a/yarn-project/circuits.js/src/contract/contract_class.ts b/yarn-project/circuits.js/src/contract/contract_class.ts index b56b96cdf6c..8d775228503 100644 --- a/yarn-project/circuits.js/src/contract/contract_class.ts +++ b/yarn-project/circuits.js/src/contract/contract_class.ts @@ -52,6 +52,6 @@ export function getContractClassFromArtifact( * Returns zero for consistency with Noir. */ function getVerificationKeyHash(_verificationKeyInBase64: string) { - // return Fr.fromBuffer(hashVKStr(verificationKeyInBase64)); + // return Fr.fromBuffer(hashVK(Buffer.from(verificationKeyInBase64, 'hex'))); return Fr.ZERO; } diff --git a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts b/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts deleted file mode 100644 index b8139394216..00000000000 --- a/yarn-project/circuits.js/src/contract/contract_tree/contract_tree.ts +++ /dev/null @@ -1,109 +0,0 @@ -import { ContractFunctionDao, Fr, FunctionData, FunctionLeafPreimage } from '@aztec/circuits.js'; -import { FunctionSelector, FunctionType } from '@aztec/foundation/abi'; - -import { hashVK } from '../../hash/hash.js'; - -/** - * Computes the hash of a hex-encoded string representation of a verification key (vk). - * The input 'vk' should be a hexadecimal string, and the resulting hash is computed using 'hashVK' function. - * Returns a Promise that resolves to a Buffer containing the hash of the verification key. - * - * @param vk - The hex-encoded string representing the verification key. - * @returns A Promise resolving to a Buffer containing the hash of the verification key. - */ -export function hashVKStr(vk: string) { - // TODO - check consistent encoding - return hashVK(Buffer.from(vk, 'hex')); -} - -/** - * Determine if the given function is a constructor. - * This utility function checks if the 'name' property of the input object is "constructor". - * Returns true if the function is a constructor, false otherwise. - * TODO(palla/purge-old-contract-deploy): Remove me - * @param Object - An object containing a 'name' property. - * @returns Boolean indicating if the function is a constructor. - */ -export function isConstructor({ - name, -}: { - /** - * Function name identifier. - */ - name: string; -}) { - return name === 'constructor'; -} - -/** - * @param Object - An object containing function name and type. - * @returns Boolean indicating if the function is constrained and therefore in the function tree. - */ -export function isConstrained({ - name, - functionType, -}: { - /** - * The name of the contract function. - */ - name: string; - /** - * The type of a contract function determining its constraints. - */ - functionType: FunctionType; -}) { - return functionType !== FunctionType.UNCONSTRAINED && !isConstructor({ name }); -} - -/** - * Generate function leaves for the constrained functions in a contract. - * Only computes leaves for functions that are either secret or open and not constructors. - * Each function leaf is computed from its selector, privacy flag, hashed verification key, and hashed bytecode. - * - * @param functions - Array of ContractFunctionDao objects representing the functions in a contract. - * @returns An array of Fr instances representing the generated function leaves. - */ -export function generateFunctionLeaves(functions: ContractFunctionDao[]) { - const targetFunctions = functions.filter(isConstrained); - const result: Fr[] = []; - for (let i = 0; i < targetFunctions.length; i++) { - const f = targetFunctions[i]; - const selector = FunctionSelector.fromNameAndParameters(f.name, f.parameters); - const isInternal = f.isInternal; - const isPrivate = f.functionType === FunctionType.SECRET; - // All non-unconstrained functions have vks - // TODO we'd need to have a defined length of the VK for this to be computed in noir - // const vkHash = hashVKStr(f.verificationKey!, wasm); - const vkHash = Buffer.alloc(32, 0); - // TODO - // FIXME: https://github.com/AztecProtocol/aztec3-packages/issues/262 - // const acirHash = keccak(Buffer.from(f.bytecode, 'hex')); - const acirHash = Buffer.alloc(32, 0); - - const fnLeafPreimage = new FunctionLeafPreimage( - selector, - isInternal, - isPrivate, - Fr.fromBuffer(vkHash), - Fr.fromBuffer(acirHash), - ); - const fnLeaf = fnLeafPreimage.hash(); - result.push(fnLeaf); - } - return result; -} - -/** - * Represents the constructor data for a new contract. - * Contains the function data and verification key hash required for contract creation. - */ -export interface NewContractConstructor { - /** - * Stores essential information about a contract function. - */ - functionData: FunctionData; - /** - * The hashed verification key of a function. - */ - vkHash: Buffer; -} diff --git a/yarn-project/circuits.js/src/contract/contract_tree/function_tree_data.test.ts b/yarn-project/circuits.js/src/contract/contract_tree/function_tree_data.test.ts deleted file mode 100644 index aac4187726f..00000000000 --- a/yarn-project/circuits.js/src/contract/contract_tree/function_tree_data.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Fr } from '@aztec/foundation/fields'; - -import { computeFunctionTreeData } from './function_tree_data.js'; - -const getFr = (index: number) => Fr.fromBuffer(Buffer.alloc(32, index)); -const Tree = [ - // leaves - getFr(8), - getFr(9), - getFr(10), - getFr(11), - getFr(12), - getFr(13), - getFr(14), - getFr(15), - // 1st hash level - getFr(4), - getFr(5), - getFr(6), - getFr(7), - // 2nd hash level - getFr(2), - getFr(3), - // root - getFr(1), -]; - -const tests = [ - { index: 0, path: [getFr(9), getFr(5), getFr(3)] }, - { index: 1, path: [getFr(8), getFr(5), getFr(3)] }, - { index: 2, path: [getFr(11), getFr(4), getFr(3)] }, - { index: 3, path: [getFr(10), getFr(4), getFr(3)] }, - { index: 4, path: [getFr(13), getFr(7), getFr(2)] }, - { index: 5, path: [getFr(12), getFr(7), getFr(2)] }, - { index: 6, path: [getFr(15), getFr(6), getFr(2)] }, - { index: 7, path: [getFr(14), getFr(6), getFr(2)] }, -]; - -describe('Compute Function Tree Sibling Path', () => { - for (let i = 0; i < tests.length; i++) { - it('should generate the correct sibling path', () => { - const actual = computeFunctionTreeData(Tree, tests[i].index); - const expected = { - root: getFr(1), - siblingPath: tests[i].path, - }; - expect(actual).toEqual(expected); - }); - } -}); diff --git a/yarn-project/circuits.js/src/contract/contract_tree/function_tree_data.ts b/yarn-project/circuits.js/src/contract/contract_tree/function_tree_data.ts deleted file mode 100644 index c377adc95bd..00000000000 --- a/yarn-project/circuits.js/src/contract/contract_tree/function_tree_data.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Fr } from '@aztec/foundation/fields'; - -/** - * Computes the root and sibling path of a given function tree and index. - * The function takes in an array of Fr elements representing the function tree and an integer function index. - * It returns an object containing the root element of the tree and an array of sibling path elements. - * - * @param functionTree - The array of Fr elements representing the function tree. - * @param functionIndex - The integer index of the desired function in the tree. - * @returns An object containing the root element (Fr) of the tree and an array of sibling path elements (Fr[]). - */ -export function computeFunctionTreeData(functionTree: Fr[], functionIndex: number) { - let rowSize = Math.ceil(functionTree.length / 2); - let rowOffset = 0; - let index = functionIndex; - const siblingPath: Fr[] = []; - while (rowSize > 1) { - const isRight = index & 1; - siblingPath.push(functionTree[rowOffset + index + (isRight ? -1 : 1)]); - rowOffset += rowSize; - rowSize >>= 1; - index >>= 1; - } - return { - root: functionTree[functionTree.length - 1], - siblingPath, - }; -} diff --git a/yarn-project/circuits.js/src/contract/contract_tree/index.ts b/yarn-project/circuits.js/src/contract/contract_tree/index.ts deleted file mode 100644 index 33534f5568c..00000000000 --- a/yarn-project/circuits.js/src/contract/contract_tree/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './contract_tree.js'; -export * from './function_tree_data.js'; diff --git a/yarn-project/circuits.js/src/contract/index.ts b/yarn-project/circuits.js/src/contract/index.ts index a72550dd8c9..2fddca8e767 100644 --- a/yarn-project/circuits.js/src/contract/index.ts +++ b/yarn-project/circuits.js/src/contract/index.ts @@ -5,6 +5,5 @@ export * from './contract_class_id.js'; export * from './contract_class_registered_event.js'; export * from './contract_instance.js'; export * from './contract_instance_deployed_event.js'; -export * from './contract_tree/index.js'; export * from './private_function.js'; export * from './public_bytecode.js';