From dc51c2bf05decdcc47e7c5f2d0794a46b62652bb Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Thu, 21 Mar 2024 19:39:27 -0300 Subject: [PATCH] chore: Remove unused FunctionLeafPreimage struct (#5354) No longer used after the new contract deployment flow. --- .../function_leaf_preimage.test.ts.snap | 3 - .../structs/function_leaf_preimage.test.ts | 35 -------- .../src/structs/function_leaf_preimage.ts | 80 ------------------- yarn-project/circuits.js/src/structs/index.ts | 1 - 4 files changed, 119 deletions(-) delete mode 100644 yarn-project/circuits.js/src/structs/__snapshots__/function_leaf_preimage.test.ts.snap delete mode 100644 yarn-project/circuits.js/src/structs/function_leaf_preimage.test.ts delete mode 100644 yarn-project/circuits.js/src/structs/function_leaf_preimage.ts diff --git a/yarn-project/circuits.js/src/structs/__snapshots__/function_leaf_preimage.test.ts.snap b/yarn-project/circuits.js/src/structs/__snapshots__/function_leaf_preimage.test.ts.snap deleted file mode 100644 index d6d47cb4160..00000000000 --- a/yarn-project/circuits.js/src/structs/__snapshots__/function_leaf_preimage.test.ts.snap +++ /dev/null @@ -1,3 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`FunctionLeafPreimage computes a function leaf 1`] = `Fr<0x1f2e3193c7187347a099ee7cb5d6ac077da6b18706fe5508e658a3d0a05494f7>`; diff --git a/yarn-project/circuits.js/src/structs/function_leaf_preimage.test.ts b/yarn-project/circuits.js/src/structs/function_leaf_preimage.test.ts deleted file mode 100644 index 1a41faa900e..00000000000 --- a/yarn-project/circuits.js/src/structs/function_leaf_preimage.test.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { FunctionSelector } from '@aztec/foundation/abi'; -import { Fr } from '@aztec/foundation/fields'; -import { setupCustomSnapshotSerializers } from '@aztec/foundation/testing'; - -import { FUNCTION_LEAF_PREIMAGE_LENGTH } from '../constants.gen.js'; -import { FunctionLeafPreimage } from './function_leaf_preimage.js'; - -describe('FunctionLeafPreimage', () => { - let leaf: FunctionLeafPreimage; - - beforeAll(() => { - setupCustomSnapshotSerializers(expect); - leaf = new FunctionLeafPreimage(new FunctionSelector(8972), false, true, Fr.ZERO, Fr.ZERO); - }); - - it(`serializes to buffer and deserializes it back`, () => { - const buffer = leaf.toBuffer(); - const res = FunctionLeafPreimage.fromBuffer(buffer); - expect(res).toEqual(leaf); - }); - - it('number of fields matches constant', () => { - const fields = leaf.toFields(); - expect(fields.length).toBe(FUNCTION_LEAF_PREIMAGE_LENGTH); - }); - - it('computes a function leaf', () => { - const emptyLeaf = new FunctionLeafPreimage(new FunctionSelector(0), false, false, Fr.ZERO, Fr.ZERO); - const hash = emptyLeaf.hash(); - expect(hash).toMatchSnapshot(); - - // Value used in empty_hash test in function_leaf_preimage.nr - // console.log("hash", hash.toString()); - }); -}); diff --git a/yarn-project/circuits.js/src/structs/function_leaf_preimage.ts b/yarn-project/circuits.js/src/structs/function_leaf_preimage.ts deleted file mode 100644 index 6a5b0f22cc8..00000000000 --- a/yarn-project/circuits.js/src/structs/function_leaf_preimage.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { FunctionSelector } from '@aztec/foundation/abi'; -import { pedersenHash } from '@aztec/foundation/crypto'; -import { Fr } from '@aztec/foundation/fields'; -import { BufferReader, serializeToBuffer, serializeToFields } from '@aztec/foundation/serialize'; -import { FieldsOf } from '@aztec/foundation/types'; - -import { FUNCTION_LEAF_PREIMAGE_LENGTH, GeneratorIndex } from '../constants.gen.js'; - -/** - * A class representing the "preimage" of a function tree leaf. - */ -export class FunctionLeafPreimage { - constructor( - /** - * Function selector. - */ - public functionSelector: FunctionSelector, - /** - * Indicates whether the function is only callable by self or not. - */ - public isInternal: boolean, - /** - * Indicates whether the function is private or public. - */ - public isPrivate: boolean, - /** - * Verification key hash of the function. - */ - public vkHash: Fr, - /** - * Hash of the ACIR of the function. - */ - public acirHash: Fr, - ) {} - - static getFields(fields: FieldsOf) { - return [fields.functionSelector, fields.isInternal, fields.isPrivate, fields.vkHash, fields.acirHash] as const; - } - - /** - * Serialize this as a buffer. - * @returns The buffer. - */ - toBuffer(): Buffer { - return serializeToBuffer(...FunctionLeafPreimage.getFields(this)); - } - - toFields(): Fr[] { - const fields = serializeToFields(...FunctionLeafPreimage.getFields(this)); - if (fields.length !== FUNCTION_LEAF_PREIMAGE_LENGTH) { - throw new Error( - `Invalid number of fields for FunctionLeafPreimage. Expected ${FUNCTION_LEAF_PREIMAGE_LENGTH}, got ${fields.length}`, - ); - } - return fields; - } - - /** - * Deserializes from a buffer or reader, corresponding to a write in cpp. - * @param buffer - Buffer or reader to read from. - * @returns A new instance of FunctionLeafPreimage. - */ - static fromBuffer(buffer: Buffer | BufferReader): FunctionLeafPreimage { - const reader = BufferReader.asReader(buffer); - return new FunctionLeafPreimage( - reader.readObject(FunctionSelector), - reader.readBoolean(), - reader.readBoolean(), - Fr.fromBuffer(reader), - Fr.fromBuffer(reader), - ); - } - - hash(): Fr { - return pedersenHash( - this.toFields().map(field => field.toBuffer()), - GeneratorIndex.FUNCTION_LEAF, - ); - } -} diff --git a/yarn-project/circuits.js/src/structs/index.ts b/yarn-project/circuits.js/src/structs/index.ts index b4a4370350d..ab67442f937 100644 --- a/yarn-project/circuits.js/src/structs/index.ts +++ b/yarn-project/circuits.js/src/structs/index.ts @@ -7,7 +7,6 @@ export * from './content_commitment.js'; export * from './contract_storage_read.js'; export * from './contract_storage_update_request.js'; export * from './function_data.js'; -export * from './function_leaf_preimage.js'; export * from './global_variables.js'; export * from './header.js'; export * from './kernel/combined_accumulated_data.js';