diff --git a/yarn-project/accounts/src/testing/configuration.ts b/yarn-project/accounts/src/testing/configuration.ts index bfd74f9912f5..6f74f3a4562c 100644 --- a/yarn-project/accounts/src/testing/configuration.ts +++ b/yarn-project/accounts/src/testing/configuration.ts @@ -9,9 +9,9 @@ import { Fr } from '@aztec/foundation/fields'; import { SchnorrAccountContractArtifact, getSchnorrAccount } from '../schnorr/index.js'; export const INITIAL_TEST_SECRET_KEYS = [ - Fr.fromString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), - Fr.fromString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'), - Fr.fromString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'), + Fr.fromHexString('2153536ff6628eee01cf4024889ff977a18d9fa61d0e414422f7681cf085c281'), + Fr.fromHexString('aebd1b4be76efa44f5ee655c20bf9ea60f7ae44b9a7fd1fd9f189c7a0b0cdae'), + Fr.fromHexString('0f6addf0da06c33293df974a565b03d1ab096090d907d98055a8b7f4954e120c'), ]; export const INITIAL_TEST_ENCRYPTION_KEYS = INITIAL_TEST_SECRET_KEYS.map(secretKey => diff --git a/yarn-project/archiver/src/archiver/archiver.ts b/yarn-project/archiver/src/archiver/archiver.ts index 94c664d0f114..f6ed51c4c192 100644 --- a/yarn-project/archiver/src/archiver/archiver.ts +++ b/yarn-project/archiver/src/archiver/archiver.ts @@ -888,7 +888,7 @@ class ArchiverStoreHelper for (const [classIdString, classEvents] of Object.entries( groupBy([...privateFnEvents, ...unconstrainedFnEvents], e => e.contractClassId.toString()), )) { - const contractClassId = Fr.fromString(classIdString); + const contractClassId = Fr.fromHexString(classIdString); const contractClass = await this.getContractClass(contractClassId); if (!contractClass) { this.#log.warn(`Skipping broadcasted functions as contract class ${contractClassId.toString()} was not found`); diff --git a/yarn-project/archiver/src/archiver/data_retrieval.ts b/yarn-project/archiver/src/archiver/data_retrieval.ts index 3249a5fc541a..abb3752765da 100644 --- a/yarn-project/archiver/src/archiver/data_retrieval.ts +++ b/yarn-project/archiver/src/archiver/data_retrieval.ts @@ -208,7 +208,7 @@ export async function retrieveL1ToL2Messages( for (const log of messageSentLogs) { const { index, hash } = log.args; - retrievedL1ToL2Messages.push(new InboxLeaf(index!, Fr.fromString(hash!))); + retrievedL1ToL2Messages.push(new InboxLeaf(index!, Fr.fromHexString(hash!))); } // handles the case when there are no new messages: @@ -235,7 +235,7 @@ export async function retrieveL2ProofVerifiedEvents( return logs.map(log => ({ l1BlockNumber: log.blockNumber, l2BlockNumber: log.args.blockNumber, - proverId: Fr.fromString(log.args.proverId), + proverId: Fr.fromHexString(log.args.proverId), txHash: log.transactionHash, })); } @@ -302,8 +302,8 @@ export async function getProofFromSubmitProofTx( ]; aggregationObject = Buffer.from(hexToBytes(decodedArgs.aggregationObject)); - proverId = Fr.fromString(decodedArgs.args[6]); - archiveRoot = Fr.fromString(decodedArgs.args[1]); + proverId = Fr.fromHexString(decodedArgs.args[6]); + archiveRoot = Fr.fromHexString(decodedArgs.args[1]); proof = Proof.fromBuffer(Buffer.from(hexToBytes(decodedArgs.proof))); } else { throw new Error(`Unexpected proof method called ${functionName}`); diff --git a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts index ce8bbb823ce9..c5a87590dfac 100644 --- a/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts +++ b/yarn-project/archiver/src/archiver/kv_archiver_store/contract_class_store.ts @@ -53,7 +53,7 @@ export class ContractClassStore { } getContractClassIds(): Fr[] { - return Array.from(this.#contractClasses.keys()).map(key => Fr.fromString(key)); + return Array.from(this.#contractClasses.keys()).map(key => Fr.fromHexString(key)); } async addFunctions( diff --git a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts index 5a0c7085c61b..72ee01540a7a 100644 --- a/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts +++ b/yarn-project/archiver/src/archiver/memory_archiver_store/memory_archiver_store.ts @@ -105,7 +105,7 @@ export class MemoryArchiverStore implements ArchiverDataStore { } public getContractClassIds(): Promise { - return Promise.resolve(Array.from(this.contractClasses.keys()).map(key => Fr.fromString(key))); + return Promise.resolve(Array.from(this.contractClasses.keys()).map(key => Fr.fromHexString(key))); } public getContractInstance(address: AztecAddress): Promise { diff --git a/yarn-project/aztec/src/cli/cmds/start_pxe.ts b/yarn-project/aztec/src/cli/cmds/start_pxe.ts index f1d8681982c5..67da2903e47b 100644 --- a/yarn-project/aztec/src/cli/cmds/start_pxe.ts +++ b/yarn-project/aztec/src/cli/cmds/start_pxe.ts @@ -93,8 +93,8 @@ export async function addPXE( l2Contracts[key] = { name: key, address: AztecAddress.fromString(basicContractsInfo[key].address), - initHash: Fr.fromString(basicContractsInfo[key].initHash), - salt: Fr.fromString(basicContractsInfo[key].salt), + initHash: Fr.fromHexString(basicContractsInfo[key].initHash), + salt: Fr.fromHexString(basicContractsInfo[key].salt), artifact: await getContractArtifact(artifactName, userLog), }; } diff --git a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts index 7f16b0292fd9..3b7b507f0a22 100644 --- a/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_private_kernel_prover.ts @@ -391,7 +391,7 @@ export class BBNativePrivateKernelProver implements PrivateKernelProver { fs.readFile(`${filePath}/${PROOF_FIELDS_FILENAME}`, { encoding: 'utf-8' }), ]); const json = JSON.parse(proofString); - const fields = json.map(Fr.fromString); + const fields = json.map(Fr.fromHexString); const numPublicInputs = vkData.numPublicInputs - AGGREGATION_OBJECT_LENGTH; const fieldsWithoutPublicInputs = fields.slice(numPublicInputs); this.log.info( diff --git a/yarn-project/bb-prover/src/prover/bb_prover.ts b/yarn-project/bb-prover/src/prover/bb_prover.ts index f737b093a382..3a795d3cb856 100644 --- a/yarn-project/bb-prover/src/prover/bb_prover.ts +++ b/yarn-project/bb-prover/src/prover/bb_prover.ts @@ -795,8 +795,8 @@ export class BBNativeRollupProver implements ServerCircuitProver { const json = JSON.parse(proofString); const fields = json .slice(0, 3) - .map(Fr.fromString) - .concat(json.slice(3 + numPublicInputs).map(Fr.fromString)); + .map(Fr.fromHexString) + .concat(json.slice(3 + numPublicInputs).map(Fr.fromHexString)); return new RecursiveProof( fields, new Proof(proof.binaryProof.buffer, vk.numPublicInputs), @@ -877,8 +877,8 @@ export class BBNativeRollupProver implements ServerCircuitProver { const fieldsWithoutPublicInputs = json .slice(0, 3) - .map(Fr.fromString) - .concat(json.slice(3 + numPublicInputs).map(Fr.fromString)); + .map(Fr.fromHexString) + .concat(json.slice(3 + numPublicInputs).map(Fr.fromHexString)); logger.debug( `Circuit path: ${filePath}, complete proof length: ${json.length}, num public inputs: ${numPublicInputs}, circuit size: ${vkData.circuitSize}, is recursive: ${vkData.isRecursive}, raw length: ${binaryProof.length}`, ); diff --git a/yarn-project/bb-prover/src/verification_key/verification_key_data.ts b/yarn-project/bb-prover/src/verification_key/verification_key_data.ts index 14f5eb28c59d..81e2f5977a8b 100644 --- a/yarn-project/bb-prover/src/verification_key/verification_key_data.ts +++ b/yarn-project/bb-prover/src/verification_key/verification_key_data.ts @@ -23,7 +23,7 @@ export async function extractVkData(vkDirectoryPath: string): Promise = { senderPrivateKey: { env: 'BOT_PRIVATE_KEY', description: 'Signing private key for the sender account.', - parseEnv: (val: string) => Fr.fromString(val), + parseEnv: (val: string) => Fr.fromHexString(val), defaultValue: Fr.random(), }, recipientEncryptionSecret: { env: 'BOT_RECIPIENT_ENCRYPTION_SECRET', description: 'Encryption secret for a recipient account.', - parseEnv: (val: string) => Fr.fromString(val), - defaultValue: Fr.fromString('0xcafecafe'), + parseEnv: (val: string) => Fr.fromHexString(val), + defaultValue: Fr.fromHexString('0xcafecafe'), }, tokenSalt: { env: 'BOT_TOKEN_SALT', description: 'Salt for the token contract deployment.', - parseEnv: (val: string) => Fr.fromString(val), - defaultValue: Fr.fromString('1'), + parseEnv: (val: string) => Fr.fromHexString(val), + defaultValue: Fr.fromHexString('1'), }, txIntervalSeconds: { env: 'BOT_TX_INTERVAL_SECONDS', diff --git a/yarn-project/circuit-types/src/interfaces/prover-client.ts b/yarn-project/circuit-types/src/interfaces/prover-client.ts index 29f8cc4fb535..5dd392d95c6f 100644 --- a/yarn-project/circuit-types/src/interfaces/prover-client.ts +++ b/yarn-project/circuit-types/src/interfaces/prover-client.ts @@ -73,7 +73,7 @@ export const proverConfigMappings: ConfigMappingsType = { }; function parseProverId(str: string) { - return Fr.fromString(str.startsWith('0x') ? str : Buffer.from(str, 'utf8').toString('hex')); + return Fr.fromHexString(str.startsWith('0x') ? str : Buffer.from(str, 'utf8').toString('hex')); } /** diff --git a/yarn-project/circuits.js/src/contract/contract_class.test.ts b/yarn-project/circuits.js/src/contract/contract_class.test.ts index 2ae16daf901c..096db939be4a 100644 --- a/yarn-project/circuits.js/src/contract/contract_class.test.ts +++ b/yarn-project/circuits.js/src/contract/contract_class.test.ts @@ -10,7 +10,7 @@ describe('ContractClass', () => { const artifact = getBenchmarkContractArtifact(); const contractClass = getContractClassFromArtifact({ ...artifact, - artifactHash: Fr.fromString('0x1234'), + artifactHash: Fr.fromHexString('0x1234'), }); // Assert bytecode has a reasonable length diff --git a/yarn-project/circuits.js/src/contract/contract_class_id.test.ts b/yarn-project/circuits.js/src/contract/contract_class_id.test.ts index 29abd4adc685..323c8783352a 100644 --- a/yarn-project/circuits.js/src/contract/contract_class_id.test.ts +++ b/yarn-project/circuits.js/src/contract/contract_class_id.test.ts @@ -8,12 +8,12 @@ describe('ContractClass', () => { it('calculates the contract class id', () => { const contractClass: ContractClass = { version: 1, - artifactHash: Fr.fromString('0x1234'), + artifactHash: Fr.fromHexString('0x1234'), packedBytecode: Buffer.from('123456789012345678901234567890', 'hex'), privateFunctions: [ { selector: FunctionSelector.fromString('0x12345678'), - vkHash: Fr.fromString('0x1234'), + vkHash: Fr.fromHexString('0x1234'), }, ], publicFunctions: [ diff --git a/yarn-project/circuits.js/src/keys/derivation.test.ts b/yarn-project/circuits.js/src/keys/derivation.test.ts index 23a230a4f2ca..6f67df60ea4e 100644 --- a/yarn-project/circuits.js/src/keys/derivation.test.ts +++ b/yarn-project/circuits.js/src/keys/derivation.test.ts @@ -11,7 +11,7 @@ describe('🔑', () => { const masterOutgoingViewingPublicKey = new Point(new Fr(5), new Fr(6), false); const masterTaggingPublicKey = new Point(new Fr(7), new Fr(8), false); - const expected = Fr.fromString('0x0fecd9a32db731fec1fded1b9ff957a1625c069245a3613a2538bd527068b0ad'); + const expected = Fr.fromHexString('0x0fecd9a32db731fec1fded1b9ff957a1625c069245a3613a2538bd527068b0ad'); expect( new PublicKeys( masterNullifierPublicKey, @@ -59,7 +59,7 @@ describe('🔑', () => { const publicKeys = new PublicKeys(npkM, ivpkM, ovpkM, tpkM); - const partialAddress = Fr.fromString('0x0a7c585381b10f4666044266a02405bf6e01fa564c8517d4ad5823493abd31de'); + const partialAddress = Fr.fromHexString('0x0a7c585381b10f4666044266a02405bf6e01fa564c8517d4ad5823493abd31de'); const address = computeAddress(publicKeys, partialAddress).toString(); expect(address).toMatchSnapshot(); diff --git a/yarn-project/circuits.js/src/structs/complete_address.test.ts b/yarn-project/circuits.js/src/structs/complete_address.test.ts index ec45caaa8d91..955a4b83d88f 100644 --- a/yarn-project/circuits.js/src/structs/complete_address.test.ts +++ b/yarn-project/circuits.js/src/structs/complete_address.test.ts @@ -40,7 +40,7 @@ describe('CompleteAddress', () => { ); const address = new AztecAddress( - Fr.fromString('0x24e4646f58b9fbe7d38e317db8d5636c423fbbdfbe119fc190fe9c64747e0c62'), + Fr.fromHexString('0x24e4646f58b9fbe7d38e317db8d5636c423fbbdfbe119fc190fe9c64747e0c62'), ); const npkM = Point.fromString( '0x22f7fcddfa3ce3e8f0cc8e82d7b94cdd740afa3e77f8e4a63ea78a239432dcab0471657de2b6216ade6c506d28fbc22ba8b8ed95c871ad9f3e3984e90d9723a7', @@ -55,7 +55,7 @@ describe('CompleteAddress', () => { '0x00d3d81beb009873eb7116327cf47c612d5758ef083d4fda78e9b63980b2a7622f567d22d2b02fe1f4ad42db9d58a36afd1983e7e2909d1cab61cafedad6193a', ); - const partialAddress = Fr.fromString('0x0a7c585381b10f4666044266a02405bf6e01fa564c8517d4ad5823493abd31de'); + const partialAddress = Fr.fromHexString('0x0a7c585381b10f4666044266a02405bf6e01fa564c8517d4ad5823493abd31de'); const completeAddressFromComponents = new CompleteAddress( address, diff --git a/yarn-project/cli-wallet/src/cmds/bridge_fee_juice.ts b/yarn-project/cli-wallet/src/cmds/bridge_fee_juice.ts index 12daf7172c39..7a4f5688e10c 100644 --- a/yarn-project/cli-wallet/src/cmds/bridge_fee_juice.ts +++ b/yarn-project/cli-wallet/src/cmds/bridge_fee_juice.ts @@ -71,7 +71,7 @@ export async function bridgeL1FeeJuice( setTimeout(async () => { const witness = await client.getL1ToL2MembershipWitness( feeJuiceAddress, - Fr.fromString(messageHash), + Fr.fromHexString(messageHash), claimSecret, ); resolve(witness); diff --git a/yarn-project/cli-wallet/src/utils/options/fees.ts b/yarn-project/cli-wallet/src/utils/options/fees.ts index fd7f73274329..ef84023d8fa2 100644 --- a/yarn-project/cli-wallet/src/utils/options/fees.ts +++ b/yarn-project/cli-wallet/src/utils/options/fees.ts @@ -164,8 +164,8 @@ export function parsePaymentMethod( } log(`Using Fee Juice for fee payments with claim for ${claimAmount} tokens`); return new FeeJuicePaymentMethodWithClaim(sender.getAddress(), { - claimAmount: typeof claimAmount === 'string' ? Fr.fromString(claimAmount) : new Fr(claimAmount), - claimSecret: Fr.fromString(claimSecret), + claimAmount: typeof claimAmount === 'string' ? Fr.fromHexString(claimAmount) : new Fr(claimAmount), + claimSecret: Fr.fromHexString(claimSecret), messageLeafIndex: BigInt(messageLeafIndex), }); } else { diff --git a/yarn-project/cli/src/utils/commands.ts b/yarn-project/cli/src/utils/commands.ts index 5bc66a8a5c0f..510d819d56a8 100644 --- a/yarn-project/cli/src/utils/commands.ts +++ b/yarn-project/cli/src/utils/commands.ts @@ -299,7 +299,7 @@ export function parsePublicKey(publicKey: string): PublicKeys | undefined { */ export function parsePartialAddress(address: string): Fr { try { - return Fr.fromString(address); + return Fr.fromHexString(address); } catch (err) { throw new InvalidArgumentError(`Invalid partial address: ${address}`); } @@ -313,7 +313,7 @@ export function parsePartialAddress(address: string): Fr { */ export function parseSecretKey(secretKey: string): Fr { try { - return Fr.fromString(secretKey); + return Fr.fromHexString(secretKey); } catch (err) { throw new InvalidArgumentError(`Invalid encryption secret key: ${secretKey}`); } @@ -329,7 +329,7 @@ export function parseField(field: string): Fr { try { const isHex = field.startsWith('0x') || field.match(new RegExp(`^[0-9a-f]{${Fr.SIZE_IN_BYTES * 2}}$`, 'i')); if (isHex) { - return Fr.fromString(field); + return Fr.fromHexString(field); } if (['true', 'false'].includes(field)) { diff --git a/yarn-project/end-to-end/src/devnet/e2e_smoke.test.ts b/yarn-project/end-to-end/src/devnet/e2e_smoke.test.ts index 3ca5e9171685..83909823d4d2 100644 --- a/yarn-project/end-to-end/src/devnet/e2e_smoke.test.ts +++ b/yarn-project/end-to-end/src/devnet/e2e_smoke.test.ts @@ -179,8 +179,8 @@ describe('End-to-end tests for devnet', () => { .deploy({ fee: { paymentMethod: new FeeJuicePaymentMethodWithClaim(l2Account.getAddress(), { - claimAmount: Fr.fromString(claimAmount), - claimSecret: Fr.fromString(claimSecret.value), + claimAmount: Fr.fromHexString(claimAmount), + claimSecret: Fr.fromHexString(claimSecret.value), messageLeafIndex: BigInt(messageLeafIndex), }), }, diff --git a/yarn-project/end-to-end/src/e2e_authwit.test.ts b/yarn-project/end-to-end/src/e2e_authwit.test.ts index c59fbef886ea..b8e19acb6f17 100644 --- a/yarn-project/end-to-end/src/e2e_authwit.test.ts +++ b/yarn-project/end-to-end/src/e2e_authwit.test.ts @@ -43,7 +43,7 @@ describe('e2e_authwit_tests', () => { // 6. We check that the authwit is NOT valid in private for wallet[1] (check that it is not signed by 1) // docs:start:compute_inner_authwit_hash - const innerHash = computeInnerAuthWitHash([Fr.fromString('0xdead')]); + const innerHash = computeInnerAuthWitHash([Fr.fromHexString('0xdead')]); // docs:end:compute_inner_authwit_hash // docs:start:compute_arbitrary_authwit_hash @@ -87,7 +87,7 @@ describe('e2e_authwit_tests', () => { }); describe('failure case', () => { it('invalid chain id', async () => { - const innerHash = computeInnerAuthWitHash([Fr.fromString('0xdead'), Fr.fromString('0xbeef')]); + const innerHash = computeInnerAuthWitHash([Fr.fromHexString('0xdead'), Fr.fromHexString('0xbeef')]); const intent = { consumer: auth.address, innerHash }; const messageHash = computeAuthWitMessageHash(intent, { chainId: Fr.random(), version }); @@ -119,7 +119,7 @@ describe('e2e_authwit_tests', () => { }); it('invalid version', async () => { - const innerHash = computeInnerAuthWitHash([Fr.fromString('0xdead'), Fr.fromString('0xbeef')]); + const innerHash = computeInnerAuthWitHash([Fr.fromHexString('0xdead'), Fr.fromHexString('0xbeef')]); const intent = { consumer: auth.address, innerHash }; const messageHash = computeAuthWitMessageHash(intent, { chainId, version: Fr.random() }); @@ -157,7 +157,7 @@ describe('e2e_authwit_tests', () => { describe('Public', () => { describe('arbitrary data', () => { it('happy path', async () => { - const innerHash = computeInnerAuthWitHash([Fr.fromString('0xdead'), Fr.fromString('0x01')]); + const innerHash = computeInnerAuthWitHash([Fr.fromHexString('0xdead'), Fr.fromHexString('0x01')]); const intent = { consumer: wallets[1].getAddress(), innerHash }; @@ -185,7 +185,7 @@ describe('e2e_authwit_tests', () => { describe('failure case', () => { it('cancel before usage', async () => { - const innerHash = computeInnerAuthWitHash([Fr.fromString('0xdead'), Fr.fromString('0x02')]); + const innerHash = computeInnerAuthWitHash([Fr.fromHexString('0xdead'), Fr.fromHexString('0x02')]); const intent = { consumer: auth.address, innerHash }; expect(await wallets[0].lookupValidity(wallets[0].getAddress(), intent)).toEqual({ diff --git a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public.test.ts b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public.test.ts index e8eff976fbbb..6f09c0bf3745 100644 --- a/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public.test.ts +++ b/yarn-project/end-to-end/src/e2e_cross_chain_messaging/token_bridge_public.test.ts @@ -48,7 +48,7 @@ describe('e2e_cross_chain_messaging token_bridge_public', () => { // 2. Deposit tokens to the TokenPortal logger.verbose(`2. Deposit tokens to the TokenPortal`); const claim = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount); - const msgHash = Fr.fromString(claim.messageHash); + const msgHash = Fr.fromHexString(claim.messageHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); // Wait for the message to be available for consumption @@ -116,7 +116,7 @@ describe('e2e_cross_chain_messaging token_bridge_public', () => { await crossChainTestHarness.mintTokensOnL1(l1TokenBalance); const claim = await crossChainTestHarness.sendTokensToPortalPublic(bridgeAmount); - const msgHash = Fr.fromString(claim.messageHash); + const msgHash = Fr.fromHexString(claim.messageHash); expect(await crossChainTestHarness.getL1BalanceOf(ethAccount)).toBe(l1TokenBalance - bridgeAmount); await crossChainTestHarness.makeMessageConsumable(msgHash); diff --git a/yarn-project/end-to-end/src/fixtures/l1_to_l2_messaging.ts b/yarn-project/end-to-end/src/fixtures/l1_to_l2_messaging.ts index b4f7c44e5dac..d61f3a62d691 100644 --- a/yarn-project/end-to-end/src/fixtures/l1_to_l2_messaging.ts +++ b/yarn-project/end-to-end/src/fixtures/l1_to_l2_messaging.ts @@ -53,5 +53,5 @@ export async function sendL1ToL2Message( const receivedMsgHash = topics.args.hash; const receivedGlobalLeafIndex = topics.args.index; - return [Fr.fromString(receivedMsgHash), new Fr(receivedGlobalLeafIndex)]; + return [Fr.fromHexString(receivedMsgHash), new Fr(receivedGlobalLeafIndex)]; } diff --git a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts index 001ecca4712b..6364517d2231 100644 --- a/yarn-project/end-to-end/src/guides/dapp_testing.test.ts +++ b/yarn-project/end-to-end/src/guides/dapp_testing.test.ts @@ -133,7 +133,7 @@ describe('guides/dapp/testing', () => { it('checks unencrypted logs, [Kinda broken with current implementation]', async () => { // docs:start:unencrypted-logs - const value = Fr.fromString('ef'); // Only 1 bytes will make its way in there :( so no larger stuff + const value = Fr.fromHexString('ef'); // Only 1 bytes will make its way in there :( so no larger stuff const tx = await testContract.methods.emit_unencrypted(value).send().wait(); const filter = { fromBlock: tx.blockNumber!, diff --git a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts index 678aeaa5682e..3ee8bc297252 100644 --- a/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts +++ b/yarn-project/end-to-end/src/guides/writing_an_account_contract.test.ts @@ -14,7 +14,7 @@ import { TokenContract } from '@aztec/noir-contracts.js/Token'; import { setup } from '../fixtures/utils.js'; // docs:start:account-contract -const PRIVATE_KEY = GrumpkinScalar.fromString('0xd35d743ac0dfe3d6dbe6be8c877cb524a00ab1e3d52d7bada095dfc8894ccfa'); +const PRIVATE_KEY = GrumpkinScalar.fromHexString('0xd35d743ac0dfe3d6dbe6be8c877cb524a00ab1e3d52d7bada095dfc8894ccfa'); /** Account contract implementation that authenticates txs using Schnorr signatures. */ class SchnorrHardcodedKeyAccountContract extends DefaultAccountContract { diff --git a/yarn-project/end-to-end/src/shared/browser.ts b/yarn-project/end-to-end/src/shared/browser.ts index ea9dde82e564..2d264468fd23 100644 --- a/yarn-project/end-to-end/src/shared/browser.ts +++ b/yarn-project/end-to-end/src/shared/browser.ts @@ -122,7 +122,7 @@ export const browserTestSuite = ( async (rpcUrl, secretKeyString) => { const { Fr, createPXEClient, getUnsafeSchnorrAccount } = window.AztecJs; const pxe = createPXEClient(rpcUrl!); - const secretKey = Fr.fromString(secretKeyString); + const secretKey = Fr.fromHexString(secretKeyString); const account = getUnsafeSchnorrAccount(pxe, secretKey); await account.waitSetup(); const completeAddress = account.getCompleteAddress(); diff --git a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts index d68750db2302..819645e81d81 100644 --- a/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts +++ b/yarn-project/end-to-end/src/shared/cross_chain_test_harness.ts @@ -354,7 +354,7 @@ export class CrossChainTestHarness { * it's included it becomes available for consumption in the next block because the l1 to l2 message tree. */ async makeMessageConsumable(msgHash: Fr | Hex) { - const frMsgHash = typeof msgHash === 'string' ? Fr.fromString(msgHash) : msgHash; + const frMsgHash = typeof msgHash === 'string' ? Fr.fromHexString(msgHash) : msgHash; // We poll isL1ToL2MessageSynced endpoint until the message is available await retryUntil(async () => await this.aztecNode.isL1ToL2MessageSynced(frMsgHash), 'message sync', 10); 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 ef6b20c00186..f914bb7954f6 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 @@ -195,7 +195,7 @@ export const uniswapL1L2TestSuite = ( wethAmountToBridge, ); - await wethCrossChainHarness.makeMessageConsumable(Fr.fromString(wethDepositClaim.messageHash)); + await wethCrossChainHarness.makeMessageConsumable(Fr.fromHexString(wethDepositClaim.messageHash)); // 2. Claim WETH on L2 logger.info('Minting weth on L2'); @@ -331,7 +331,7 @@ export const uniswapL1L2TestSuite = ( // We get the msg leaf from event so that we can later wait for it to be available for consumption const inboxAddress = daiCrossChainHarness.l1ContractAddresses.inboxAddress.toString(); const txLog = extractEvent(txReceipt.logs, inboxAddress, InboxAbi, 'MessageSent'); - const tokenOutMsgHash = Fr.fromString(txLog.args.hash); + const tokenOutMsgHash = Fr.fromHexString(txLog.args.hash); const tokenOutMsgIndex = txLog.args.index; // weth was swapped to dai and send to portal @@ -559,7 +559,7 @@ export const uniswapL1L2TestSuite = ( // data: txLog.data, // topics: txLog.topics, // }); - // outTokenDepositMsgHash = Fr.fromString(topics.args.hash); + // outTokenDepositMsgHash = Fr.fromHexString(topics.args.hash); // } // // weth was swapped to dai and send to portal diff --git a/yarn-project/foundation/src/abi/encoder.ts b/yarn-project/foundation/src/abi/encoder.ts index 5f876a0e35d2..f62cb2b22e98 100644 --- a/yarn-project/foundation/src/abi/encoder.ts +++ b/yarn-project/foundation/src/abi/encoder.ts @@ -49,7 +49,7 @@ class ArgumentEncoder { } else if (typeof arg === 'bigint') { this.flattened.push(new Fr(arg)); } else if (typeof arg === 'string') { - this.flattened.push(Fr.fromString(arg)); + this.flattened.push(Fr.fromHexString(arg)); } else if (typeof arg === 'boolean') { this.flattened.push(new Fr(arg ? 1n : 0n)); } else if (typeof arg === 'object') { @@ -58,7 +58,7 @@ class ArgumentEncoder { } else if (typeof arg.toField === 'function') { this.flattened.push(arg.toField()); } else if (typeof arg.value === 'string') { - this.flattened.push(Fr.fromString(arg.value)); + this.flattened.push(Fr.fromHexString(arg.value)); } else { throw new Error(`Argument for ${name} cannot be serialized to a field`); } diff --git a/yarn-project/foundation/src/fields/fields.test.ts b/yarn-project/foundation/src/fields/fields.test.ts index 491b0d797567..6501a91be080 100644 --- a/yarn-project/foundation/src/fields/fields.test.ts +++ b/yarn-project/foundation/src/fields/fields.test.ts @@ -27,7 +27,7 @@ describe('GrumpkinScalar Serialization', () => { it('fromString should serialize and deserialize correctly', () => { const original = GrumpkinScalar.random(); const hexString = original.toString(); - const deserialized = GrumpkinScalar.fromString(hexString); + const deserialized = GrumpkinScalar.fromHexString(hexString); // Check if the deserialized instance is equal to the original expect(deserialized).toEqual(original); @@ -37,12 +37,12 @@ describe('GrumpkinScalar Serialization', () => { const arbitraryHexString = '0x123'; const expectedBigInt = 291n; - expect(GrumpkinScalar.fromString(arbitraryString).toBigInt()).toEqual(expectedBigInt); - expect(GrumpkinScalar.fromString(arbitraryHexString).toBigInt()).toEqual(expectedBigInt); + expect(GrumpkinScalar.fromHexString(arbitraryString).toBigInt()).toEqual(expectedBigInt); + expect(GrumpkinScalar.fromHexString(arbitraryHexString).toBigInt()).toEqual(expectedBigInt); const incorrectlyFormattedString = '12xx34xx45'; - expect(() => GrumpkinScalar.fromString(incorrectlyFormattedString).toBigInt()).toThrow(); + expect(() => GrumpkinScalar.fromHexString(incorrectlyFormattedString).toBigInt()).toThrow(); }); // Test case for GrumpkinScalar.toBuffer @@ -59,7 +59,7 @@ describe('GrumpkinScalar Serialization', () => { it('toString should serialize and deserialize correctly', () => { const original = GrumpkinScalar.random(); const hexString = original.toString(); - const deserialized = GrumpkinScalar.fromString(hexString); + const deserialized = GrumpkinScalar.fromHexString(hexString); // Check if the deserialized instance is equal to the original expect(deserialized).toEqual(original); diff --git a/yarn-project/foundation/src/fields/fields.ts b/yarn-project/foundation/src/fields/fields.ts index 84b559c4f3c9..59921b2a5129 100644 --- a/yarn-project/foundation/src/fields/fields.ts +++ b/yarn-project/foundation/src/fields/fields.ts @@ -232,12 +232,31 @@ export class Fr extends BaseField { return fromBufferReduce(buffer, Fr); } + /** + * Creates a Fr instance from a string. + * @param buf - the string to create a Fr from. + * @returns the Fr instance + * @remarks if the string only consists of numbers, we assume we are parsing a bigint, + * otherwise we require the hex string to be prepended with "0x", to ensure there is no misunderstanding + * as to what is being parsed. + */ + static fromString(buf: string) { + if (buf.match(/^\d+$/) !== null) { + return new Fr(BigInt(buf)); + } + if (buf.match(/^0x/i) !== null) { + return fromHexString(buf, Fr); + } + + throw new Error('Tried to create a Fr from an invalid string'); + } + /** * Creates a Fr instance from a hex string. * @param buf - a hex encoded string. * @returns the Fr instance */ - static fromString(buf: string) { + static fromHexString(buf: string) { return fromHexString(buf, Fr); } @@ -368,12 +387,31 @@ export class Fq extends BaseField { return fromBufferReduce(buffer, Fq); } + /** + * Creates a Fq instance from a string. + * @param buf - the string to create a Fq from. + * @returns the Fq instance + * @remarks if the string only consists of numbers, we assume we are parsing a bigint, + * otherwise we require the hex string to be prepended with "0x", to ensure there is no misunderstanding + * as to what is being parsed. + */ + static fromString(buf: string) { + if (buf.match(/^\d+$/) !== null) { + return new Fq(BigInt(buf)); + } + if (buf.match(/^0x/i) !== null) { + return fromHexString(buf, Fq); + } + + throw new Error('Tried to create a F1 from an invalid string'); + } + /** * Creates a Fq instance from a hex string. * @param buf - a hex encoded string. * @returns the Fq instance */ - static fromString(buf: string) { + static fromHexString(buf: string) { return fromHexString(buf, Fq); } diff --git a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts index a0a2573e9e0a..9cfcb0da5b70 100644 --- a/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts +++ b/yarn-project/noir-protocol-circuits-types/src/scripts/generate_vk_hashes.ts @@ -33,7 +33,7 @@ const main = async () => { if (!content.vkHash) { const { keyAsFields } = content; - content.vkHash = hashVK(keyAsFields.map((str: string) => Fr.fromString(str))).toString(); + content.vkHash = hashVK(keyAsFields.map((str: string) => Fr.fromHexString(str))).toString(); await fs.writeFile(keyPath, JSON.stringify(content, null, 2)); } } diff --git a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts index 77ec114a2a84..8f6d1ad55770 100644 --- a/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts +++ b/yarn-project/noir-protocol-circuits-types/src/type_conversion.ts @@ -255,7 +255,7 @@ export function mapFieldToNoir(field: Fr): NoirField { * @returns The fr. */ export function mapFieldFromNoir(field: NoirField): Fr { - return Fr.fromString(field); + return Fr.fromHexString(field); } /** Maps a field to a noir wrapped field type (ie any type implemented as struct with an inner Field). */ @@ -274,7 +274,7 @@ export function mapWrappedFieldFromNoir(wrappedField: { inner: NoirField }): Fr * @returns The number */ export function mapNumberFromNoir(number: NoirField): number { - return Number(Fr.fromString(number).toBigInt()); + return Number(Fr.fromHexString(number).toBigInt()); } export function mapNumberToNoir(number: number): NoirField { diff --git a/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts b/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts index 2640a9e5cbb5..50d6a8e17974 100644 --- a/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts +++ b/yarn-project/noir-protocol-circuits-types/src/utils/vk_json.ts @@ -10,8 +10,8 @@ export function keyJsonToVKData(json: VkJson): VerificationKeyData { const { keyAsBytes, keyAsFields, vkHash } = json; return new VerificationKeyData( new VerificationKeyAsFields( - keyAsFields.map((str: string) => Fr.fromString(str)), - Fr.fromString(vkHash), + keyAsFields.map((str: string) => Fr.fromHexString(str)), + Fr.fromHexString(vkHash), ), Buffer.from(keyAsBytes, 'hex'), ); diff --git a/yarn-project/protocol-contracts/src/scripts/generate_data.ts b/yarn-project/protocol-contracts/src/scripts/generate_data.ts index eebd16860fe6..31ac0b5f8c95 100644 --- a/yarn-project/protocol-contracts/src/scripts/generate_data.ts +++ b/yarn-project/protocol-contracts/src/scripts/generate_data.ts @@ -137,7 +137,7 @@ function generateContractAddresses(names: string[]) { function generateContractLeaves(names: string[], leaves: Fr[]) { return ` export const ProtocolContractLeaf = { - ${leaves.map((leaf, i) => `${names[i]}: Fr.fromString('${leaf.toString()}')`).join(',\n')} + ${leaves.map((leaf, i) => `${names[i]}: Fr.fromHexString('${leaf.toString()}')`).join(',\n')} }; `; } @@ -145,7 +145,7 @@ function generateContractLeaves(names: string[], leaves: Fr[]) { function generateRoot(names: string[], leaves: Fr[]) { const root = computeRoot(names, leaves); return ` - export const protocolContractTreeRoot = Fr.fromString('${root.toString()}'); + export const protocolContractTreeRoot = Fr.fromHexString('${root.toString()}'); `; } @@ -154,7 +154,7 @@ function generateLogTags() { export const REGISTERER_CONTRACT_CLASS_REGISTERED_TAG = new Fr(${REGISTERER_CONTRACT_CLASS_REGISTERED_MAGIC_VALUE}n); export const REGISTERER_PRIVATE_FUNCTION_BROADCASTED_TAG = new Fr(${REGISTERER_PRIVATE_FUNCTION_BROADCASTED_MAGIC_VALUE}n); export const REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_TAG = new Fr(${REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_MAGIC_VALUE}n); - export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG = Fr.fromString('${poseidon2Hash([ + export const DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_TAG = Fr.fromHexString('${poseidon2Hash([ DEPLOYER_CONTRACT_ADDRESS, DEPLOYER_CONTRACT_INSTANCE_DEPLOYED_MAGIC_VALUE, ])}'); diff --git a/yarn-project/pxe/src/database/incoming_note_dao.ts b/yarn-project/pxe/src/database/incoming_note_dao.ts index d2dc2d388153..f2952fc8f000 100644 --- a/yarn-project/pxe/src/database/incoming_note_dao.ts +++ b/yarn-project/pxe/src/database/incoming_note_dao.ts @@ -78,7 +78,7 @@ export class IncomingNoteDao implements NoteData { this.noteTypeId, this.txHash.buffer, this.l2BlockNumber, - Fr.fromString(this.l2BlockHash), + Fr.fromHexString(this.l2BlockHash), this.nonce, this.noteHash, this.siloedNullifier, diff --git a/yarn-project/pxe/src/database/outgoing_note_dao.ts b/yarn-project/pxe/src/database/outgoing_note_dao.ts index 386b23ecd573..211c66cea7b0 100644 --- a/yarn-project/pxe/src/database/outgoing_note_dao.ts +++ b/yarn-project/pxe/src/database/outgoing_note_dao.ts @@ -71,7 +71,7 @@ export class OutgoingNoteDao { this.noteTypeId, this.txHash.buffer, this.l2BlockNumber, - Fr.fromString(this.l2BlockHash), + Fr.fromHexString(this.l2BlockHash), this.nonce, this.noteHash, this.index, diff --git a/yarn-project/pxe/src/simulator_oracle/index.ts b/yarn-project/pxe/src/simulator_oracle/index.ts index 4a18b6bf7581..4af6ee1352e2 100644 --- a/yarn-project/pxe/src/simulator_oracle/index.ts +++ b/yarn-project/pxe/src/simulator_oracle/index.ts @@ -506,7 +506,7 @@ export class SimulatorOracle implements DBOracle { }); await this.db.setTaggingSecretsIndexesAsRecipient( Object.keys(secretsToIncrement).map( - secret => new IndexedTaggingSecret(Fr.fromString(secret), secretsToIncrement[secret]), + secret => new IndexedTaggingSecret(Fr.fromHexString(secret), secretsToIncrement[secret]), ), ); currentTagggingSecrets = newTaggingSecrets; diff --git a/yarn-project/sequencer-client/src/config.ts b/yarn-project/sequencer-client/src/config.ts index 761300832115..0d8ca0a8d2bd 100644 --- a/yarn-project/sequencer-client/src/config.ts +++ b/yarn-project/sequencer-client/src/config.ts @@ -189,12 +189,12 @@ export function parseSequencerAllowList(value: string): AllowedElement[] { } else if (typeString === 'C') { if (selector) { entries.push({ - classId: Fr.fromString(identifierString), + classId: Fr.fromHexString(identifierString), selector, }); } else { entries.push({ - classId: Fr.fromString(identifierString), + classId: Fr.fromHexString(identifierString), }); } } diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index b1e0aa5a50cf..e7a45df38fa3 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -675,7 +675,7 @@ export class L1Publisher { : proof.extractAggregationObject(); const argsPublicInputs = [...publicInputs.toFields(), ...aggregationObject]; - if (!areArraysEqual(rollupPublicInputs.map(Fr.fromString), argsPublicInputs, (a, b) => a.equals(b))) { + if (!areArraysEqual(rollupPublicInputs.map(Fr.fromHexString), argsPublicInputs, (a, b) => a.equals(b))) { const fmt = (inputs: Fr[] | readonly string[]) => inputs.map(x => x.toString()).join(', '); throw new Error( `Root rollup public inputs mismatch:\nRollup: ${fmt(rollupPublicInputs)}\nComputed:${fmt(argsPublicInputs)}`, diff --git a/yarn-project/simulator/src/acvm/serialize.ts b/yarn-project/simulator/src/acvm/serialize.ts index 4e84ccac128e..0ae28ed6ce5c 100644 --- a/yarn-project/simulator/src/acvm/serialize.ts +++ b/yarn-project/simulator/src/acvm/serialize.ts @@ -32,7 +32,7 @@ export function toACVMField( } else if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'bigint') { buffer = new Fr(value).toBuffer(); } else if (typeof value === 'string') { - buffer = Fr.fromString(value).toBuffer(); + buffer = Fr.fromHexString(value).toBuffer(); } else { buffer = value.toBuffer(); } diff --git a/yarn-project/simulator/src/client/private_execution.test.ts b/yarn-project/simulator/src/client/private_execution.test.ts index 815f48c36bba..ac64d92c77eb 100644 --- a/yarn-project/simulator/src/client/private_execution.test.ts +++ b/yarn-project/simulator/src/client/private_execution.test.ts @@ -86,8 +86,8 @@ describe('Private Execution test suite', () => { let logger: DebugLogger; const defaultContractAddress = AztecAddress.random(); - const ownerSk = Fr.fromString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); - const recipientSk = Fr.fromString('0c9ed344548e8f9ba8aa3c9f8651eaa2853130f6c1e9c050ccf198f7ea18a7ec'); + const ownerSk = Fr.fromHexString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); + const recipientSk = Fr.fromHexString('0c9ed344548e8f9ba8aa3c9f8651eaa2853130f6c1e9c050ccf198f7ea18a7ec'); let owner: AztecAddress; let recipient: AztecAddress; let ownerCompleteAddress: CompleteAddress; diff --git a/yarn-project/simulator/src/client/simulator.test.ts b/yarn-project/simulator/src/client/simulator.test.ts index 951899e10a3f..30cb6d85b6d9 100644 --- a/yarn-project/simulator/src/client/simulator.test.ts +++ b/yarn-project/simulator/src/client/simulator.test.ts @@ -20,7 +20,7 @@ describe('Simulator', () => { let appNullifierSecretKey: Fr; beforeEach(() => { - const ownerSk = Fr.fromString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); + const ownerSk = Fr.fromHexString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); const allOwnerKeys = deriveKeys(ownerSk); ownerMasterNullifierPublicKey = allOwnerKeys.publicKeys.masterNullifierPublicKey; diff --git a/yarn-project/simulator/src/client/unconstrained_execution.test.ts b/yarn-project/simulator/src/client/unconstrained_execution.test.ts index 99bb3e3842d2..ac266e198614 100644 --- a/yarn-project/simulator/src/client/unconstrained_execution.test.ts +++ b/yarn-project/simulator/src/client/unconstrained_execution.test.ts @@ -27,7 +27,7 @@ describe('Unconstrained Execution test suite', () => { }); describe('private token contract', () => { - const ownerSecretKey = Fr.fromString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); + const ownerSecretKey = Fr.fromHexString('2dcc5485a58316776299be08c78fa3788a1a7961ae30dc747fb1be17692a8d32'); let owner: AztecAddress;