diff --git a/yarn-project/accounts/src/defaults/account_entrypoint.ts b/yarn-project/accounts/src/defaults/account_entrypoint.ts index 67b62181dfd5..f64db020b70e 100644 --- a/yarn-project/accounts/src/defaults/account_entrypoint.ts +++ b/yarn-project/accounts/src/defaults/account_entrypoint.ts @@ -1,6 +1,6 @@ import { AuthWitnessProvider, EntrypointInterface, FeeOptions } from '@aztec/aztec.js/account'; import { FunctionCall, PackedArguments, TxExecutionRequest } from '@aztec/circuit-types'; -import { AztecAddress, Fr, FunctionData, GeneratorIndex, TxContext } from '@aztec/circuits.js'; +import { AztecAddress, FunctionData, GeneratorIndex, TxContext } from '@aztec/circuits.js'; import { FunctionAbi, encodeArguments } from '@aztec/foundation/abi'; import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js'; @@ -25,12 +25,8 @@ export class DefaultAccountEntrypoint implements EntrypointInterface { const abi = this.getEntrypointAbi(); const entrypointPackedArgs = PackedArguments.fromArgs(encodeArguments(abi, [appPayload, feePayload])); - const appAuthWitness = await this.auth.createAuthWitness( - Fr.fromBuffer(hashPayload(appPayload, GeneratorIndex.SIGNATURE_PAYLOAD)), - ); - const feeAuthWitness = await this.auth.createAuthWitness( - Fr.fromBuffer(hashPayload(feePayload, GeneratorIndex.FEE_PAYLOAD)), - ); + const appAuthWitness = await this.auth.createAuthWitness(hashPayload(appPayload, GeneratorIndex.SIGNATURE_PAYLOAD)); + const feeAuthWitness = await this.auth.createAuthWitness(hashPayload(feePayload, GeneratorIndex.FEE_PAYLOAD)); const txRequest = TxExecutionRequest.from({ argsHash: entrypointPackedArgs.hash, diff --git a/yarn-project/aztec.js/src/utils/cheat_codes.ts b/yarn-project/aztec.js/src/utils/cheat_codes.ts index 02ce3e565493..b22aa828bee5 100644 --- a/yarn-project/aztec.js/src/utils/cheat_codes.ts +++ b/yarn-project/aztec.js/src/utils/cheat_codes.ts @@ -246,7 +246,7 @@ export class AztecCheatCodes { public computeSlotInMap(baseSlot: Fr | bigint, key: Fr | bigint | AztecAddress): Fr { // Based on `at` function in // aztec3-packages/aztec-nr/aztec/src/state_vars/map.nr - return Fr.fromBuffer(pedersenHash([new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer()))); + return pedersenHash([new Fr(baseSlot), new Fr(key)].map(f => f.toBuffer())); } /** diff --git a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts index db68e95f98df..5787e13e7b15 100644 --- a/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_blacklist_token_contract.test.ts @@ -813,7 +813,7 @@ describe('e2e_blacklist_token_contract', () => { ); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, + `Unknown auth witness for message hash 0x${messageHash.toString()}`, ); }); @@ -840,7 +840,7 @@ describe('e2e_blacklist_token_contract', () => { ); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${expectedMessageHash.toString('hex')}`, + `Unknown auth witness for message hash 0x${expectedMessageHash.toString()}`, ); expect(await asset.methods.balance_of_private(accounts[0].address).view()).toEqual(balance0); }); @@ -1147,7 +1147,7 @@ describe('e2e_blacklist_token_contract', () => { ); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${expectedMessageHash.toString('hex')}`, + `Unknown auth witness for message hash 0x${expectedMessageHash.toString()}`, ); }); @@ -1386,7 +1386,7 @@ describe('e2e_blacklist_token_contract', () => { const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, + `Unknown auth witness for message hash 0x${messageHash.toString()}`, ); }); @@ -1408,7 +1408,7 @@ describe('e2e_blacklist_token_contract', () => { await wallets[2].addAuthWitness(witness); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${expectedMessageHash.toString('hex')}`, + `Unknown auth witness for message hash 0x${expectedMessageHash.toString()}`, ); }); diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts index 9e5932e00d4e..8d5a9418c92b 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging.test.ts @@ -203,7 +203,7 @@ describe('e2e_cross_chain_messaging', () => { .withWallet(user1Wallet) .methods.exit_to_l1_private(l2Token.address, ethAccount, withdrawAmount, EthAddress.ZERO, nonce) .simulate(), - ).rejects.toThrowError(`Unknown auth witness for message hash 0x${expectedBurnMessageHash.toString('hex')}`); + ).rejects.toThrowError(`Unknown auth witness for message hash 0x${expectedBurnMessageHash.toString()}`); }, 120_000); it("Can't claim funds publicly if they were deposited privately", async () => { diff --git a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts index a33526523edf..10c6cbae525c 100644 --- a/yarn-project/end-to-end/src/e2e_lending_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_lending_contract.test.ts @@ -172,7 +172,7 @@ describe('e2e_lending_contract', () => { .request(), ); - await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); + await wallet.createAuthWitness(messageHash); await lendingSim.progressTime(TIME_JUMP); lendingSim.depositPrivate(lendingAccount.address, lendingAccount.key(), depositAmount); @@ -205,7 +205,7 @@ describe('e2e_lending_contract', () => { .unshield(lendingAccount.address, lendingContract.address, depositAmount, nonce) .request(), ); - await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); + await wallet.createAuthWitness(messageHash); await lendingSim.progressTime(TIME_JUMP); lendingSim.depositPrivate(lendingAccount.address, lendingAccount.address.toField(), depositAmount); @@ -303,7 +303,7 @@ describe('e2e_lending_contract', () => { lendingContract.address, stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce).request(), ); - await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); + await wallet.createAuthWitness(messageHash); await lendingSim.progressTime(TIME_JUMP); lendingSim.repayPrivate(lendingAccount.address, lendingAccount.key(), repayAmount); @@ -329,7 +329,7 @@ describe('e2e_lending_contract', () => { lendingContract.address, stableCoin.methods.burn(lendingAccount.address, repayAmount, nonce).request(), ); - await wallet.createAuthWitness(Fr.fromBuffer(messageHash)); + await wallet.createAuthWitness(messageHash); await lendingSim.progressTime(TIME_JUMP); lendingSim.repayPrivate(lendingAccount.address, lendingAccount.address.toField(), repayAmount); diff --git a/yarn-project/end-to-end/src/e2e_token_contract.test.ts b/yarn-project/end-to-end/src/e2e_token_contract.test.ts index 42792edbe753..bb667a391791 100644 --- a/yarn-project/end-to-end/src/e2e_token_contract.test.ts +++ b/yarn-project/end-to-end/src/e2e_token_contract.test.ts @@ -614,7 +614,7 @@ describe('e2e_token_contract', () => { const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, + `Unknown auth witness for message hash ${messageHash.toString()}`, ); }); @@ -635,7 +635,7 @@ describe('e2e_token_contract', () => { await wallets[2].addAuthWitness(witness); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${expectedMessageHash.toString('hex')}`, + `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); expect(await asset.methods.balance_of_private(accounts[0].address).view()).toEqual(balance0); }); @@ -874,7 +874,7 @@ describe('e2e_token_contract', () => { await wallets[2].addAuthWitness(witness); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${expectedMessageHash.toString('hex')}`, + `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); }); @@ -1062,7 +1062,7 @@ describe('e2e_token_contract', () => { const messageHash = computeAuthWitMessageHash(accounts[1].address, action.request()); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${messageHash.toString('hex')}`, + `Unknown auth witness for message hash ${messageHash.toString()}`, ); }); @@ -1081,7 +1081,7 @@ describe('e2e_token_contract', () => { await wallets[2].addAuthWitness(witness); await expect(action.simulate()).rejects.toThrowError( - `Unknown auth witness for message hash 0x${expectedMessageHash.toString('hex')}`, + `Unknown auth witness for message hash ${expectedMessageHash.toString()}`, ); }); }); diff --git a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts index cbf7df990026..9a5669165d47 100644 --- a/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts +++ b/yarn-project/end-to-end/src/shared/uniswap_l1_l2.ts @@ -206,7 +206,7 @@ export const uniswapL1L2TestSuite = ( .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) .request(), ); - await ownerWallet.createAuthWitness(Fr.fromBuffer(unshieldToUniswapMessageHash)); + await ownerWallet.createAuthWitness(unshieldToUniswapMessageHash); // 4. Swap on L1 - sends L2 to L1 message to withdraw WETH to L1 and another message to swap assets. logger('Withdrawing weth to L1 and sending message to swap to dai'); @@ -475,7 +475,7 @@ export const uniswapL1L2TestSuite = ( ownerEthAddress, ) .simulate(), - ).rejects.toThrowError(`Unknown auth witness for message hash 0x${expectedMessageHash.toString('hex')}`); + ).rejects.toThrowError(`Unknown auth witness for message hash ${expectedMessageHash.toString()}`); }); it("can't swap if user passes a token different to what the bridge tracks", async () => { @@ -494,7 +494,7 @@ export const uniswapL1L2TestSuite = ( .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) .request(), ); - await ownerWallet.createAuthWitness(Fr.fromBuffer(unshieldToUniswapMessageHash)); + await ownerWallet.createAuthWitness(unshieldToUniswapMessageHash); // 3. Swap but send the wrong token address logger('Swap but send the wrong token address'); @@ -644,7 +644,7 @@ export const uniswapL1L2TestSuite = ( .unshield(ownerAddress, uniswapL2Contract.address, wethAmountToBridge, nonceForWETHUnshieldApproval) .request(), ); - await ownerWallet.createAuthWitness(Fr.fromBuffer(unshieldToUniswapMessageHash)); + await ownerWallet.createAuthWitness(unshieldToUniswapMessageHash); const wethL2BalanceBeforeSwap = await wethCrossChainHarness.getL2PrivateBalanceOf(ownerAddress); // Swap diff --git a/yarn-project/end-to-end/src/simulators/lending_simulator.ts b/yarn-project/end-to-end/src/simulators/lending_simulator.ts index dcc91fa28a12..2a0da49ed1d0 100644 --- a/yarn-project/end-to-end/src/simulators/lending_simulator.ts +++ b/yarn-project/end-to-end/src/simulators/lending_simulator.ts @@ -24,7 +24,7 @@ export class LendingAccount { * @returns Key in public space */ public key() { - return Fr.fromBuffer(pedersenHash([this.address, this.secret].map(f => f.toBuffer()))); + return pedersenHash([this.address, this.secret].map(f => f.toBuffer())); } } diff --git a/yarn-project/foundation/src/crypto/poseidon/index.ts b/yarn-project/foundation/src/crypto/poseidon/index.ts index 7cc44a95b5e6..8f77b5802115 100644 --- a/yarn-project/foundation/src/crypto/poseidon/index.ts +++ b/yarn-project/foundation/src/crypto/poseidon/index.ts @@ -1,13 +1,17 @@ -import { BarretenbergSync, Fr } from '@aztec/bb.js'; +import { BarretenbergSync, Fr as FrBarretenberg } from '@aztec/bb.js'; + +import { Fr } from '../../fields/fields.js'; /** * Create a poseidon hash (field) from an array of input fields. * Left pads any inputs less than 32 bytes. */ -export function poseidonHash(input: Buffer[]): Buffer { - return Buffer.from( - BarretenbergSync.getSingleton() - .poseidonHash(input.map(i => new Fr(i))) - .toBuffer(), +export function poseidonHash(input: Buffer[]): Fr { + return Fr.fromBuffer( + Buffer.from( + BarretenbergSync.getSingleton() + .poseidonHash(input.map(i => new FrBarretenberg(i))) + .toBuffer(), + ), ); } diff --git a/yarn-project/merkle-tree/src/pedersen.ts b/yarn-project/merkle-tree/src/pedersen.ts index 2cc990049702..b4a749e5a8a8 100644 --- a/yarn-project/merkle-tree/src/pedersen.ts +++ b/yarn-project/merkle-tree/src/pedersen.ts @@ -12,7 +12,7 @@ export class Pedersen implements Hasher { * purposes. */ public hash(lhs: Uint8Array, rhs: Uint8Array): Buffer { - return pedersenHash([Buffer.from(lhs), Buffer.from(rhs)]); + return pedersenHash([Buffer.from(lhs), Buffer.from(rhs)]).toBuffer(); } /* @@ -20,6 +20,6 @@ export class Pedersen implements Hasher { * purposes. */ public hashInputs(inputs: Buffer[]): Buffer { - return pedersenHash(inputs); + return pedersenHash(inputs).toBuffer(); } } diff --git a/yarn-project/pxe/src/note_processor/note_processor.test.ts b/yarn-project/pxe/src/note_processor/note_processor.test.ts index 3770584959c4..6c66111c2b08 100644 --- a/yarn-project/pxe/src/note_processor/note_processor.test.ts +++ b/yarn-project/pxe/src/note_processor/note_processor.test.ts @@ -43,7 +43,7 @@ describe('Note Processor', () => { const firstBlockDataStartIndex = (firstBlockNum - 1) * numCommitmentsPerBlock; const firstBlockDataEndIndex = firstBlockNum * numCommitmentsPerBlock; - const computeMockNoteHash = (note: Note) => Fr.fromBuffer(pedersenHash(note.items.map(i => i.toBuffer()))); + const computeMockNoteHash = (note: Note) => pedersenHash(note.items.map(i => i.toBuffer())); // ownedData: [tx1, tx2, ...], the numbers in each tx represents the indices of the note hashes the account owns. const createEncryptedLogsAndOwnedL1NotePayloads = (ownedData: number[][], ownedNotes: L1NotePayload[]) => { diff --git a/yarn-project/simulator/src/avm/avm_simulator.test.ts b/yarn-project/simulator/src/avm/avm_simulator.test.ts index 8a56550155ae..bfe7b98f704c 100644 --- a/yarn-project/simulator/src/avm/avm_simulator.test.ts +++ b/yarn-project/simulator/src/avm/avm_simulator.test.ts @@ -118,7 +118,7 @@ describe('AVM simulator', () => { describe.each([ ['avm_poseidon_hash', poseidonHash], ['avm_pedersen_hash', pedersenHash], - ])('Hashes with field returned in noir contracts', (name: string, hashFunction: (data: Buffer[]) => Buffer) => { + ])('Hashes with field returned in noir contracts', (name: string, hashFunction: (data: Buffer[]) => Fr) => { it(`Should execute contract function that performs ${name} hash`, async () => { const calldata = [new Fr(1), new Fr(2), new Fr(3)]; const hash = hashFunction(calldata.map(f => f.toBuffer())); diff --git a/yarn-project/simulator/src/avm/opcodes/hashing.test.ts b/yarn-project/simulator/src/avm/opcodes/hashing.test.ts index 0c7b363df048..25e4a71a68e7 100644 --- a/yarn-project/simulator/src/avm/opcodes/hashing.test.ts +++ b/yarn-project/simulator/src/avm/opcodes/hashing.test.ts @@ -45,7 +45,7 @@ describe('Hashing Opcodes', () => { await new Poseidon2(indirect, dstOffset, hashOffset, args.length).execute(context); const result = context.machineState.memory.get(dstOffset); - expect(result).toEqual(new Field(toBigIntBE(expectedHash))); + expect(result).toEqual(new Field(expectedHash)); }); it('Should hash correctly - indirect', async () => { @@ -63,7 +63,7 @@ describe('Hashing Opcodes', () => { await new Poseidon2(indirect, dstOffset, hashOffset, args.length).execute(context); const result = context.machineState.memory.get(dstOffset); - expect(result).toEqual(new Field(toBigIntBE(expectedHash))); + expect(result).toEqual(new Field(expectedHash)); }); }); @@ -225,7 +225,7 @@ describe('Hashing Opcodes', () => { await new Pedersen(indirect, dstOffset, hashOffset, args.length).execute(context); const result = context.machineState.memory.get(dstOffset); - expect(result).toEqual(new Field(toBigIntBE(expectedHash))); + expect(result).toEqual(new Field(expectedHash)); }); it('Should hash correctly - indirect', async () => { @@ -244,7 +244,7 @@ describe('Hashing Opcodes', () => { await new Pedersen(indirect, dstOffset, hashOffset, args.length).execute(context); const result = context.machineState.memory.get(dstOffset); - expect(result).toEqual(new Field(toBigIntBE(expectedHash))); + expect(result).toEqual(new Field(expectedHash)); }); }); }); diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 501c5b908a47..a8e03dcdfc59 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -178,7 +178,7 @@ describe('Private Execution test suite', () => { return trees[name]; }; - const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHash(data.map(f => f.toBuffer()))); + const hashFields = (data: Fr[]) => pedersenHash(data.map(f => f.toBuffer())); beforeAll(() => { logger = createDebugLogger('aztec:test:private_execution'); diff --git a/yarn-project/simulator/src/client/simulator.test.ts b/yarn-project/simulator/src/client/simulator.test.ts index 4eec4b5a3d17..b8192633373a 100644 --- a/yarn-project/simulator/src/client/simulator.test.ts +++ b/yarn-project/simulator/src/client/simulator.test.ts @@ -23,7 +23,7 @@ describe('Simulator', () => { const ownerNullifierSecretKey = GrumpkinScalar.random(); const ownerNullifierPublicKey = Point.random(); - const hashFields = (data: Fr[]) => Fr.fromBuffer(pedersenHash(data.map(f => f.toBuffer()))); + const hashFields = (data: Fr[]) => pedersenHash(data.map(f => f.toBuffer())); beforeEach(() => { oracle = mock(); diff --git a/yarn-project/simulator/src/public/index.test.ts b/yarn-project/simulator/src/public/index.test.ts index 4a528e1f1873..860520256684 100644 --- a/yarn-project/simulator/src/public/index.test.ts +++ b/yarn-project/simulator/src/public/index.test.ts @@ -332,7 +332,7 @@ describe('ACIR public execution simulator', () => { const expectedNoteHash = pedersenHash([amount.toBuffer(), secretHash.toBuffer()]); const storageSlot = new Fr(5); // for pending_shields - const expectedInnerNoteHash = pedersenHash([storageSlot.toBuffer(), expectedNoteHash]); + const expectedInnerNoteHash = pedersenHash([storageSlot, expectedNoteHash].map(f => f.toBuffer())); expect(result.newCommitments[0].value.toBuffer()).toEqual(expectedInnerNoteHash); }); @@ -365,7 +365,7 @@ describe('ACIR public execution simulator', () => { const expectedNewMessage = new L2ToL1Message( portalContractAddress, - Fr.fromBuffer(pedersenHash(params.map(a => a.toBuffer()))), + pedersenHash(params.map(a => a.toBuffer())), ); expect(result.newL2ToL1Messages[0]).toEqual(expectedNewMessage); @@ -478,7 +478,7 @@ describe('ACIR public execution simulator', () => { let root = messageKey ?? preimage.hash(); for (const sibling of siblingPathBuffers) { - root = Fr.fromBuffer(pedersenHash([root.toBuffer(), sibling])); + root = pedersenHash([root.toBuffer(), sibling]); } commitmentsDb.getL1ToL2Message.mockImplementation(() => { return Promise.resolve(new MessageLoadOracleInputs(preimage, 0n, siblingPath)); diff --git a/yarn-project/simulator/src/utils.ts b/yarn-project/simulator/src/utils.ts index a47e4e390ba3..ad65917f0130 100644 --- a/yarn-project/simulator/src/utils.ts +++ b/yarn-project/simulator/src/utils.ts @@ -14,5 +14,5 @@ export function computeSlotForMapping( toField: () => Fr; }, ) { - return Fr.fromBuffer(pedersenHash([mappingSlot, key.toField()].map(field => field.toBuffer()))); + return pedersenHash([mappingSlot, key.toField()].map(field => field.toBuffer())); }