diff --git a/avm-transpiler/Cargo.lock b/avm-transpiler/Cargo.lock index 11767391c57..4997bffb9e3 100644 --- a/avm-transpiler/Cargo.lock +++ b/avm-transpiler/Cargo.lock @@ -305,12 +305,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.7" @@ -863,18 +857,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "jsonrpc" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34efde8d2422fb79ed56db1d3aea8fa5b583351d15a26770cdee2f88813dd702" -dependencies = [ - "base64 0.13.1", - "minreq", - "serde", - "serde_json", -] - [[package]] name = "k256" version = "0.11.6" @@ -929,17 +911,6 @@ dependencies = [ "adler", ] -[[package]] -name = "minreq" -version = "2.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "763d142cdff44aaadd9268bebddb156ef6c65a0e13486bb81673cf2d8739f9b0" -dependencies = [ - "log", - "serde", - "serde_json", -] - [[package]] name = "noirc_errors" version = "1.0.0-beta.1" @@ -962,11 +933,7 @@ name = "noirc_printable_type" version = "1.0.0-beta.1" dependencies = [ "acvm", - "iter-extended", - "jsonrpc", "serde", - "serde_json", - "thiserror", ] [[package]] diff --git a/cspell.json b/cspell.json index 3ed9bc44cf4..9acd495666a 100644 --- a/cspell.json +++ b/cspell.json @@ -12,6 +12,7 @@ "auditability", "authwit", "authwits", + "authwitness", "Automine", "autonat", "autorun", diff --git a/l1-contracts/src/core/libraries/RollupLibs/ProposeLib.sol b/l1-contracts/src/core/libraries/RollupLibs/ProposeLib.sol index 59b4e10a7a6..5dbc8b27dae 100644 --- a/l1-contracts/src/core/libraries/RollupLibs/ProposeLib.sol +++ b/l1-contracts/src/core/libraries/RollupLibs/ProposeLib.sol @@ -15,6 +15,6 @@ struct ProposeArgs { library ProposeLib { function digest(ProposeArgs memory _args) internal pure returns (bytes32) { - return keccak256(abi.encode(SignatureLib.SignatureDomainSeperator.blockAttestation, _args)); + return keccak256(abi.encode(SignatureLib.SignatureDomainSeparator.blockAttestation, _args)); } } diff --git a/l1-contracts/src/core/libraries/crypto/SignatureLib.sol b/l1-contracts/src/core/libraries/crypto/SignatureLib.sol index 4223f5ddafe..1265adb305f 100644 --- a/l1-contracts/src/core/libraries/crypto/SignatureLib.sol +++ b/l1-contracts/src/core/libraries/crypto/SignatureLib.sol @@ -13,9 +13,9 @@ struct Signature { library SignatureLib { /** - * @notice The domain seperator for the signatures + * @notice The domain separator for the signatures */ - enum SignatureDomainSeperator { + enum SignatureDomainSeparator { blockProposal, blockAttestation } diff --git a/noir-projects/aztec-nr/aztec/src/keys/secret_derivation.nr b/noir-projects/aztec-nr/aztec/src/keys/secret_derivation.nr index b49fa90a783..93201448573 100644 --- a/noir-projects/aztec-nr/aztec/src/keys/secret_derivation.nr +++ b/noir-projects/aztec-nr/aztec/src/keys/secret_derivation.nr @@ -11,7 +11,7 @@ pub fn derive_aes_secret(secret: Scalar, point: Point) -> [u8; 32] { } shared_secret_bytes_with_separator[32] = GENERATOR_INDEX__SYMMETRIC_KEY; - + // TODO(https://github.com/AztecProtocol/aztec-packages/issues/10537): Replace use of sha256 sha256(shared_secret_bytes_with_separator) } diff --git a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr index 5d8aa114b09..1b9577a0b63 100644 --- a/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr +++ b/noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr @@ -441,7 +441,7 @@ comptime fn generate_setup_payload( + 2 /* log_plaintext_length */ + 14 /* AES padding */; // Each field contains 31 bytes so the length in fields is computed as ceil(encrypted_log_byte_length / 31) - // --> we achieve rouding by adding 30 and then dividing without remainder + // --> we achieve rounding by adding 30 and then dividing without remainder let encrypted_log_field_length = (encrypted_log_byte_length + 30) / 31; ( @@ -661,7 +661,7 @@ comptime fn generate_finalization_payload( + 2 /* log_plaintext_length */ + 14 /* AES padding */; // Each field contains 31 bytes so the length in fields is computed as ceil(setup_log_byte_length / 31) - // --> we achieve rouding by adding 30 and then dividing without remainder + // --> we achieve rounding by adding 30 and then dividing without remainder let setup_log_field_length = (setup_log_byte_length + 30) / 31; let public_values_field_length = public_values_length * 32; let finalization_log_byte_length = diff --git a/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr b/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr index b14258f9d0f..a70d9ebeada 100644 --- a/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/amm_contract/src/main.nr @@ -253,7 +253,7 @@ contract AMM { let sender = context.msg_sender(); // Liquidity tokens are burned when liquidity is removed in order to reduce the total supply. However, we lack - // a function to privately burn, so we instead transfer the tokens into the AMM's public balance, and them have + // a function to privately burn, so we instead transfer the tokens into the AMM's public balance, and then have // the AMM publicly burn its own tokens. // TODO(#10287): consider adding a private burn liquidity_token.transfer_to_public(sender, context.this_address(), liquidity, nonce).call( diff --git a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr index e7298d32e3c..e2927543213 100644 --- a/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr +++ b/noir-projects/noir-contracts/contracts/token_bridge_contract/src/main.nr @@ -95,7 +95,6 @@ contract TokenBridge { /// Claims the bridged tokens and makes them accessible in private. Note that recipient's address is not revealed /// but the amount is. Hence it's most likely possible to determine to which L1 deposit this claim corresponds to /// (unless there are multiple pending deposits of the same amount). - /// TODO(#8416): Consider creating a truly private claim flow. #[private] fn claim_private( recipient: AztecAddress, // recipient of the bridged tokens diff --git a/noir-projects/noir-protocol-circuits/.gitignore b/noir-projects/noir-protocol-circuits/.gitignore index 9a99d303b90..5782711af5d 100644 --- a/noir-projects/noir-protocol-circuits/.gitignore +++ b/noir-projects/noir-protocol-circuits/.gitignore @@ -2,4 +2,5 @@ Verifier.toml target crates/autogenerated /Nargo.toml -/private_kernel_reset_dimensions.json \ No newline at end of file +/private_kernel_reset_dimensions.json +install-state.gz \ No newline at end of file diff --git a/noir-projects/noir-protocol-circuits/.yarn/install-state.gz b/noir-projects/noir-protocol-circuits/.yarn/install-state.gz deleted file mode 100644 index 5c46fdd2fed..00000000000 Binary files a/noir-projects/noir-protocol-circuits/.yarn/install-state.gz and /dev/null differ diff --git a/noir-projects/noir-protocol-circuits/package.json b/noir-projects/noir-protocol-circuits/package.json index 2f5efb48850..0fe327c2d05 100644 --- a/noir-projects/noir-protocol-circuits/package.json +++ b/noir-projects/noir-protocol-circuits/package.json @@ -4,5 +4,6 @@ "main": "index.js", "dependencies": { "@iarna/toml": "^2.2.5" - } + }, + "packageManager": "yarn@4.5.2+sha512.570504f67349ef26d2d86a768dc5ec976ead977aa086b0bb4237e97d5db7ae5c620f9f0e0edf3ea5047205063faff102bf2a2d778664a94eaaa1085ad483fe2e" } diff --git a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts index 50730dbb56e..5f9cd2f6b0b 100644 --- a/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts +++ b/yarn-project/archiver/src/archiver/archiver_store_test_suite.ts @@ -29,7 +29,7 @@ import { makeUnconstrainedFunctionWithMembershipProof, } from '@aztec/circuits.js/testing'; import { times } from '@aztec/foundation/collection'; -import { randomBytes, randomInt } from '@aztec/foundation/crypto'; +import { randomInt } from '@aztec/foundation/crypto'; import { type ArchiverDataStore, type ArchiverL1SynchPoint } from './archiver_store.js'; import { type L1Published } from './structs/published.js'; @@ -223,7 +223,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch }); it('returns undefined if tx is not found', async () => { - await expect(store.getTxEffect(new TxHash(Fr.random().toBuffer()))).resolves.toBeUndefined(); + await expect(store.getTxEffect(TxHash.random())).resolves.toBeUndefined(); }); it.each([ @@ -241,7 +241,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch }); it('returns undefined if tx is not found', async () => { - await expect(store.getTxEffect(new TxHash(Fr.random().toBuffer()))).resolves.toBeUndefined(); + await expect(store.getTxEffect(TxHash.random())).resolves.toBeUndefined(); }); }); @@ -645,7 +645,7 @@ export function describeArchiverDataStore(testName: string, getStore: () => Arch it('"txHash" filter param is ignored when "afterLog" is set', async () => { // Get random txHash - const txHash = new TxHash(randomBytes(TxHash.SIZE)); + const txHash = TxHash.random(); const afterLog = new LogId(1, 0, 0); const response = await store.getUnencryptedLogs({ txHash, afterLog }); diff --git a/yarn-project/aztec.js/src/contract/sent_tx.test.ts b/yarn-project/aztec.js/src/contract/sent_tx.test.ts index c0f7daf8a57..2d03462f19f 100644 --- a/yarn-project/aztec.js/src/contract/sent_tx.test.ts +++ b/yarn-project/aztec.js/src/contract/sent_tx.test.ts @@ -1,4 +1,5 @@ import { type PXE, TxHash, type TxReceipt, TxStatus } from '@aztec/circuit-types'; +import { Fr } from '@aztec/circuits.js'; import { type MockProxy, mock } from 'jest-mock-extended'; @@ -12,7 +13,7 @@ describe('SentTx', () => { beforeEach(() => { pxe = mock(); - txHashPromise = Promise.resolve(TxHash.fromBigInt(1n)); + txHashPromise = Promise.resolve(new TxHash(new Fr(1n))); sentTx = new SentTx(pxe, txHashPromise); }); diff --git a/yarn-project/aztec/package.json b/yarn-project/aztec/package.json index 714b0362802..559d5343028 100644 --- a/yarn-project/aztec/package.json +++ b/yarn-project/aztec/package.json @@ -17,6 +17,7 @@ "build": "yarn clean && tsc -b", "start": "node --no-warnings ./dest/bin", "start:debug": "node --inspect=0.0.0.0:9221 --no-warnings ./dest/bin", + "start:sandbox": "ETHEREUM_HOST=http://0.0.0.0:8545/ && yarn start start --sandbox", "clean": "rm -rf ./dest .tsbuildinfo", "formatting": "run -T prettier --check ./src && run -T eslint ./src", "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src", diff --git a/yarn-project/circuit-types/src/interfaces/archiver.test.ts b/yarn-project/circuit-types/src/interfaces/archiver.test.ts index 4824b95365a..05ad8002117 100644 --- a/yarn-project/circuit-types/src/interfaces/archiver.test.ts +++ b/yarn-project/circuit-types/src/interfaces/archiver.test.ts @@ -100,12 +100,12 @@ describe('ArchiverApiSchema', () => { }); it('getTxEffect', async () => { - const result = await context.client.getTxEffect(new TxHash(Buffer.alloc(32, 1))); + const result = await context.client.getTxEffect(TxHash.fromBuffer(Buffer.alloc(32, 1))); expect(result!.data).toBeInstanceOf(TxEffect); }); it('getSettledTxReceipt', async () => { - const result = await context.client.getSettledTxReceipt(new TxHash(Buffer.alloc(32, 1))); + const result = await context.client.getSettledTxReceipt(TxHash.fromBuffer(Buffer.alloc(32, 1))); expect(result).toBeInstanceOf(TxReceipt); }); diff --git a/yarn-project/circuit-types/src/logs/get_logs_response.ts b/yarn-project/circuit-types/src/logs/get_logs_response.ts index 62b2ff6d833..13aab991d0d 100644 --- a/yarn-project/circuit-types/src/logs/get_logs_response.ts +++ b/yarn-project/circuit-types/src/logs/get_logs_response.ts @@ -73,7 +73,7 @@ export class TxScopedL2Log { static fromBuffer(buffer: Buffer) { const reader = BufferReader.asReader(buffer); return new TxScopedL2Log( - TxHash.fromField(reader.readObject(Fr)), + reader.readObject(TxHash), reader.readNumber(), reader.readNumber(), reader.readBoolean(), diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index 9909b1e179e..54b55ca1e5d 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -34,7 +34,7 @@ import { PublicExecutionRequest } from './public_execution_request.js'; import { PublicSimulationOutput, Tx, TxHash, TxSimulationResult, accumulatePrivateReturnValues } from './tx/index.js'; import { TxEffect } from './tx_effect.js'; -export const randomTxHash = (): TxHash => new TxHash(randomBytes(32)); +export const randomTxHash = (): TxHash => TxHash.random(); export const mockPrivateExecutionResult = ( seed = 1, diff --git a/yarn-project/circuit-types/src/notes/extended_note.ts b/yarn-project/circuit-types/src/notes/extended_note.ts index cac982b01b8..85c8bda5ed2 100644 --- a/yarn-project/circuit-types/src/notes/extended_note.ts +++ b/yarn-project/circuit-types/src/notes/extended_note.ts @@ -1,7 +1,7 @@ import { AztecAddress, Fr } from '@aztec/circuits.js'; import { NoteSelector } from '@aztec/foundation/abi'; import { schemas } from '@aztec/foundation/schemas'; -import { BufferReader } from '@aztec/foundation/serialize'; +import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { bufferToHex, hexToBuffer } from '@aztec/foundation/string'; import { z } from 'zod'; @@ -29,25 +29,25 @@ export class ExtendedNote { ) {} toBuffer(): Buffer { - return Buffer.concat([ - this.note.toBuffer(), - this.owner.toBuffer(), - this.contractAddress.toBuffer(), - this.storageSlot.toBuffer(), - this.noteTypeId.toBuffer(), - this.txHash.buffer, + return serializeToBuffer([ + this.note, + this.owner, + this.contractAddress, + this.storageSlot, + this.noteTypeId, + this.txHash, ]); } static fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); - const note = Note.fromBuffer(reader); - const owner = AztecAddress.fromBuffer(reader); - const contractAddress = AztecAddress.fromBuffer(reader); - const storageSlot = Fr.fromBuffer(reader); + const note = reader.readObject(Note); + const owner = reader.readObject(AztecAddress); + const contractAddress = reader.readObject(AztecAddress); + const storageSlot = reader.readObject(Fr); const noteTypeId = reader.readObject(NoteSelector); - const txHash = new TxHash(reader.readBytes(TxHash.SIZE)); + const txHash = reader.readObject(TxHash); return new this(note, owner, contractAddress, storageSlot, noteTypeId, txHash); } @@ -124,14 +124,14 @@ export class UniqueNote extends ExtendedNote { } override toBuffer(): Buffer { - return Buffer.concat([ - this.note.toBuffer(), - this.owner.toBuffer(), - this.contractAddress.toBuffer(), - this.storageSlot.toBuffer(), - this.noteTypeId.toBuffer(), - this.txHash.buffer, - this.nonce.toBuffer(), + return serializeToBuffer([ + this.note, + this.owner, + this.contractAddress, + this.storageSlot, + this.noteTypeId, + this.txHash, + this.nonce, ]); } @@ -150,13 +150,13 @@ export class UniqueNote extends ExtendedNote { static override fromBuffer(buffer: Buffer | BufferReader) { const reader = BufferReader.asReader(buffer); - const note = Note.fromBuffer(reader); - const owner = AztecAddress.fromBuffer(reader); - const contractAddress = AztecAddress.fromBuffer(reader); - const storageSlot = Fr.fromBuffer(reader); + const note = reader.readObject(Note); + const owner = reader.readObject(AztecAddress); + const contractAddress = reader.readObject(AztecAddress); + const storageSlot = reader.readObject(Fr); const noteTypeId = reader.readObject(NoteSelector); - const txHash = new TxHash(reader.readBytes(TxHash.SIZE)); - const nonce = Fr.fromBuffer(reader); + const txHash = reader.readObject(TxHash); + const nonce = reader.readObject(Fr); return new this(note, owner, contractAddress, storageSlot, noteTypeId, txHash, nonce); } diff --git a/yarn-project/circuit-types/src/p2p/block_attestation.ts b/yarn-project/circuit-types/src/p2p/block_attestation.ts index 4ac0babe690..d4fea987a54 100644 --- a/yarn-project/circuit-types/src/p2p/block_attestation.ts +++ b/yarn-project/circuit-types/src/p2p/block_attestation.ts @@ -10,7 +10,7 @@ import { z } from 'zod'; import { ConsensusPayload } from './consensus_payload.js'; import { Gossipable } from './gossipable.js'; -import { SignatureDomainSeperator, getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js'; +import { SignatureDomainSeparator, getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js'; import { TopicType, createTopicString } from './topic_type.js'; export class BlockAttestationHash extends Buffer32 { @@ -65,7 +65,7 @@ export class BlockAttestation extends Gossipable { getSender() { if (!this.sender) { // Recover the sender from the attestation - const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeperator.blockAttestation); + const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockAttestation); // Cache the sender for later use this.sender = recoverAddress(hashed, this.signature); } @@ -74,7 +74,7 @@ export class BlockAttestation extends Gossipable { } getPayload(): Buffer { - return this.payload.getPayloadToSign(SignatureDomainSeperator.blockAttestation); + return this.payload.getPayloadToSign(SignatureDomainSeparator.blockAttestation); } toBuffer(): Buffer { diff --git a/yarn-project/circuit-types/src/p2p/block_proposal.ts b/yarn-project/circuit-types/src/p2p/block_proposal.ts index 207312ba4a1..b65b0870833 100644 --- a/yarn-project/circuit-types/src/p2p/block_proposal.ts +++ b/yarn-project/circuit-types/src/p2p/block_proposal.ts @@ -8,7 +8,7 @@ import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { ConsensusPayload } from './consensus_payload.js'; import { Gossipable } from './gossipable.js'; import { - SignatureDomainSeperator, + SignatureDomainSeparator, getHashedSignaturePayload, getHashedSignaturePayloadEthSignedMessage, } from './signature_utils.js'; @@ -57,7 +57,7 @@ export class BlockProposal extends Gossipable { payload: ConsensusPayload, payloadSigner: (payload: Buffer32) => Promise, ) { - const hashed = getHashedSignaturePayload(payload, SignatureDomainSeperator.blockProposal); + const hashed = getHashedSignaturePayload(payload, SignatureDomainSeparator.blockProposal); const sig = await payloadSigner(hashed); return new BlockProposal(payload, sig); @@ -68,7 +68,7 @@ export class BlockProposal extends Gossipable { */ getSender() { if (!this.sender) { - const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeperator.blockProposal); + const hashed = getHashedSignaturePayloadEthSignedMessage(this.payload, SignatureDomainSeparator.blockProposal); // Cache the sender for later use this.sender = recoverAddress(hashed, this.signature); } @@ -77,7 +77,7 @@ export class BlockProposal extends Gossipable { } getPayload() { - return this.payload.getPayloadToSign(SignatureDomainSeperator.blockProposal); + return this.payload.getPayloadToSign(SignatureDomainSeparator.blockProposal); } toBuffer(): Buffer { diff --git a/yarn-project/circuit-types/src/p2p/consensus_payload.ts b/yarn-project/circuit-types/src/p2p/consensus_payload.ts index 37fedc508da..b1e72369013 100644 --- a/yarn-project/circuit-types/src/p2p/consensus_payload.ts +++ b/yarn-project/circuit-types/src/p2p/consensus_payload.ts @@ -8,7 +8,7 @@ import { encodeAbiParameters, parseAbiParameters } from 'viem'; import { z } from 'zod'; import { TxHash } from '../tx/tx_hash.js'; -import { type Signable, type SignatureDomainSeperator } from './signature_utils.js'; +import { type Signable, type SignatureDomainSeparator } from './signature_utils.js'; export class ConsensusPayload implements Signable { private size: number | undefined; @@ -36,11 +36,11 @@ export class ConsensusPayload implements Signable { return [fields.header, fields.archive, fields.txHashes] as const; } - getPayloadToSign(domainSeperator: SignatureDomainSeperator): Buffer { + getPayloadToSign(domainSeparator: SignatureDomainSeparator): Buffer { const abi = parseAbiParameters('uint8, (bytes32, bytes32, (uint256, uint256), bytes, bytes32[])'); const txArray = this.txHashes.map(tx => tx.toString()); const encodedData = encodeAbiParameters(abi, [ - domainSeperator, + domainSeparator, [ this.archive.toString(), this.header.hash().toString(), diff --git a/yarn-project/circuit-types/src/p2p/mocks.ts b/yarn-project/circuit-types/src/p2p/mocks.ts index 1e4e99ac042..8896980843b 100644 --- a/yarn-project/circuit-types/src/p2p/mocks.ts +++ b/yarn-project/circuit-types/src/p2p/mocks.ts @@ -7,7 +7,7 @@ import { TxHash } from '../tx/tx_hash.js'; import { BlockAttestation } from './block_attestation.js'; import { BlockProposal } from './block_proposal.js'; import { ConsensusPayload } from './consensus_payload.js'; -import { SignatureDomainSeperator, getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js'; +import { SignatureDomainSeparator, getHashedSignaturePayloadEthSignedMessage } from './signature_utils.js'; export interface MakeConsensusPayloadOptions { signer?: Secp256k1Signer; @@ -17,7 +17,7 @@ export interface MakeConsensusPayloadOptions { } const makeAndSignConsensusPayload = ( - domainSeperator: SignatureDomainSeperator, + domainSeparator: SignatureDomainSeparator, options?: MakeConsensusPayloadOptions, ) => { const { @@ -33,19 +33,19 @@ const makeAndSignConsensusPayload = ( txHashes, }); - const hash = getHashedSignaturePayloadEthSignedMessage(payload, domainSeperator); + const hash = getHashedSignaturePayloadEthSignedMessage(payload, domainSeparator); const signature = signer.sign(hash); return { payload, signature }; }; export const makeBlockProposal = (options?: MakeConsensusPayloadOptions): BlockProposal => { - const { payload, signature } = makeAndSignConsensusPayload(SignatureDomainSeperator.blockProposal, options); + const { payload, signature } = makeAndSignConsensusPayload(SignatureDomainSeparator.blockProposal, options); return new BlockProposal(payload, signature); }; // TODO(https://github.com/AztecProtocol/aztec-packages/issues/8028) export const makeBlockAttestation = (options?: MakeConsensusPayloadOptions): BlockAttestation => { - const { payload, signature } = makeAndSignConsensusPayload(SignatureDomainSeperator.blockAttestation, options); + const { payload, signature } = makeAndSignConsensusPayload(SignatureDomainSeparator.blockAttestation, options); return new BlockAttestation(payload, signature); }; diff --git a/yarn-project/circuit-types/src/p2p/signature_utils.ts b/yarn-project/circuit-types/src/p2p/signature_utils.ts index 25e20ded5d8..4c05ccb3823 100644 --- a/yarn-project/circuit-types/src/p2p/signature_utils.ts +++ b/yarn-project/circuit-types/src/p2p/signature_utils.ts @@ -1,13 +1,13 @@ import { Buffer32 } from '@aztec/foundation/buffer'; import { keccak256, makeEthSignDigest } from '@aztec/foundation/crypto'; -export enum SignatureDomainSeperator { +export enum SignatureDomainSeparator { blockProposal = 0, blockAttestation = 1, } export interface Signable { - getPayloadToSign(domainSeperator: SignatureDomainSeperator): Buffer; + getPayloadToSign(domainSeparator: SignatureDomainSeparator): Buffer; } /** @@ -15,8 +15,8 @@ export interface Signable { * @param s - The `Signable` to sign * @returns The hashed payload for the signature of the `Signable` */ -export function getHashedSignaturePayload(s: Signable, domainSeperator: SignatureDomainSeperator): Buffer32 { - return Buffer32.fromBuffer(keccak256(s.getPayloadToSign(domainSeperator))); +export function getHashedSignaturePayload(s: Signable, domainSeparator: SignatureDomainSeparator): Buffer32 { + return Buffer32.fromBuffer(keccak256(s.getPayloadToSign(domainSeparator))); } /** @@ -26,8 +26,8 @@ export function getHashedSignaturePayload(s: Signable, domainSeperator: Signatur */ export function getHashedSignaturePayloadEthSignedMessage( s: Signable, - domainSeperator: SignatureDomainSeperator, + domainSeparator: SignatureDomainSeparator, ): Buffer32 { - const payload = getHashedSignaturePayload(s, domainSeperator); + const payload = getHashedSignaturePayload(s, domainSeparator); return makeEthSignDigest(payload); } diff --git a/yarn-project/circuit-types/src/tx/processed_tx.ts b/yarn-project/circuit-types/src/tx/processed_tx.ts index ddbc926647c..b9c4c465333 100644 --- a/yarn-project/circuit-types/src/tx/processed_tx.ts +++ b/yarn-project/circuit-types/src/tx/processed_tx.ts @@ -103,7 +103,7 @@ export function makeEmptyProcessedTx( clientProofOutput.constants = constants; return { - hash: new TxHash(Fr.ZERO.toBuffer()), + hash: new TxHash(Fr.ZERO), data: clientProofOutput, clientIvcProof: ClientIvcProof.empty(), avmProvingRequest: undefined, diff --git a/yarn-project/circuit-types/src/tx/tx.ts b/yarn-project/circuit-types/src/tx/tx.ts index 1e8a03107d1..4f95a81af7b 100644 --- a/yarn-project/circuit-types/src/tx/tx.ts +++ b/yarn-project/circuit-types/src/tx/tx.ts @@ -4,7 +4,7 @@ import { type PrivateToPublicAccumulatedData, type ScopedLogHash, } from '@aztec/circuits.js'; -import { type Buffer32 } from '@aztec/foundation/buffer'; +import { Buffer32 } from '@aztec/foundation/buffer'; import { arraySerializedSizeOfNonEmpty } from '@aztec/foundation/collection'; import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize'; import { type FieldsOf } from '@aztec/foundation/types'; @@ -65,7 +65,7 @@ export class Tx extends Gossipable { // Gossipable method override p2pMessageIdentifier(): Buffer32 { - return this.getTxHash(); + return new Buffer32(this.getTxHash().toBuffer()); } hasPublicCalls() { @@ -176,7 +176,7 @@ export class Tx extends Gossipable { if (!firstNullifier || firstNullifier.isZero()) { throw new Error(`Cannot get tx hash since first nullifier is missing`); } - return new TxHash(firstNullifier.toBuffer()); + return new TxHash(firstNullifier); } /** Returns the tx hash, or undefined if none is set. */ diff --git a/yarn-project/circuit-types/src/tx/tx_hash.ts b/yarn-project/circuit-types/src/tx/tx_hash.ts index f2477823ab2..797733689ed 100644 --- a/yarn-project/circuit-types/src/tx/tx_hash.ts +++ b/yarn-project/circuit-types/src/tx/tx_hash.ts @@ -1,32 +1,66 @@ import { Fr } from '@aztec/circuits.js'; -import { Buffer32 } from '@aztec/foundation/buffer'; import { schemas } from '@aztec/foundation/schemas'; +import { BufferReader } from '@aztec/foundation/serialize'; /** * A class representing hash of Aztec transaction. */ -export class TxHash extends Buffer32 { +export class TxHash { constructor( - /** The buffer containing the hash. */ - hash: Buffer, - ) { - super(hash); - } + /** A field representing the tx hash (tx hash is an output of poseidon hash hence it's a field). */ + public readonly hash: Fr, + ) {} /* * TxHashes are generated from the first nullifier of a transaction, which is a Fr. - * Using Buffer32.random() could potentially generate invalid TxHashes. * @returns A random TxHash. */ - static override random() { - return new TxHash(Fr.random().toBuffer()); + static random() { + return new TxHash(Fr.random()); + } + + static fromBuffer(buffer: Uint8Array | BufferReader) { + const reader = BufferReader.asReader(buffer); + return new this(reader.readObject(Fr)); + } + + static fromString(str: string) { + return new TxHash(Fr.fromString(str)); + } + + static fromBigInt(value: bigint) { + return new TxHash(new Fr(value)); + } + + public toBuffer() { + return this.hash.toBuffer(); + } + + public toString() { + return this.hash.toString(); + } + + public toBigInt() { + return this.hash.toBigInt(); + } + + toJSON() { + return this.toString(); + } + + public equals(other: TxHash) { + return this.hash.equals(other.hash); } static get schema() { - return schemas.BufferHex.transform(value => new TxHash(value)); + return schemas.BufferHex.transform(value => new TxHash(Fr.fromBuffer(value))); } static zero() { - return new TxHash(Buffer32.ZERO.toBuffer()); + return new TxHash(Fr.ZERO); + } + + static get SIZE() { + return Fr.SIZE_IN_BYTES; } } diff --git a/yarn-project/circuit-types/src/tx_effect.ts b/yarn-project/circuit-types/src/tx_effect.ts index 924f2e5bc95..d0ae676ad39 100644 --- a/yarn-project/circuit-types/src/tx_effect.ts +++ b/yarn-project/circuit-types/src/tx_effect.ts @@ -550,6 +550,6 @@ export class TxEffect { } get txHash(): TxHash { - return new TxHash(this.nullifiers[0].toBuffer()); + return new TxHash(this.nullifiers[0]); } } diff --git a/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts b/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts index a8ea957cfeb..0d4d0092b8b 100644 --- a/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts +++ b/yarn-project/circuits.js/src/contract/interfaces/contract_instance.ts @@ -24,7 +24,7 @@ export interface ContractInstance { contractClassId: Fr; /** Hash of the selector and arguments to the constructor. */ initializationHash: Fr; - /** Public keys associated with this intsance. */ + /** Public keys associated with this instance. */ publicKeys: PublicKeys; } diff --git a/yarn-project/end-to-end/src/e2e_p2p/reex.test.ts b/yarn-project/end-to-end/src/e2e_p2p/reex.test.ts index be5475755c0..b91d154f1dc 100644 --- a/yarn-project/end-to-end/src/e2e_p2p/reex.test.ts +++ b/yarn-project/end-to-end/src/e2e_p2p/reex.test.ts @@ -2,7 +2,7 @@ import { type AztecNodeService } from '@aztec/aztec-node'; import { type SentTx, sleep } from '@aztec/aztec.js'; /* eslint-disable-next-line no-restricted-imports */ -import { BlockProposal, SignatureDomainSeperator, getHashedSignaturePayload } from '@aztec/circuit-types'; +import { BlockProposal, SignatureDomainSeparator, getHashedSignaturePayload } from '@aztec/circuit-types'; import { beforeAll, describe, it, jest } from '@jest/globals'; import fs from 'fs'; @@ -92,7 +92,7 @@ describe('e2e_p2p_reex', () => { const signer = (node as any).sequencer.sequencer.validatorClient.validationService.keyStore; const newProposal = new BlockProposal( proposal.payload, - await signer.signMessage(getHashedSignaturePayload(proposal.payload, SignatureDomainSeperator.blockProposal)), + await signer.signMessage(getHashedSignaturePayload(proposal.payload, SignatureDomainSeparator.blockProposal)), ); return (node as any).p2pClient.p2pService.propagate(newProposal); diff --git a/yarn-project/foundation/src/fields/point.ts b/yarn-project/foundation/src/fields/point.ts index 96135f47b50..e950998350b 100644 --- a/yarn-project/foundation/src/fields/point.ts +++ b/yarn-project/foundation/src/fields/point.ts @@ -10,6 +10,7 @@ import { Fr } from './fields.js'; * Represents a Point on an elliptic curve with x and y coordinates. * The Point class provides methods for creating instances from different input types, * converting instances to various output formats, and checking the equality of points. + * TODO(#7386): Clean up this class. */ export class Point { static ZERO = new Point(Fr.ZERO, Fr.ZERO, false); diff --git a/yarn-project/p2p/src/mem_pools/attestation_pool/mocks.ts b/yarn-project/p2p/src/mem_pools/attestation_pool/mocks.ts index 8a1b60a9ffd..7cbf84dfcbe 100644 --- a/yarn-project/p2p/src/mem_pools/attestation_pool/mocks.ts +++ b/yarn-project/p2p/src/mem_pools/attestation_pool/mocks.ts @@ -1,7 +1,7 @@ import { BlockAttestation, ConsensusPayload, - SignatureDomainSeperator, + SignatureDomainSeparator, TxHash, getHashedSignaturePayloadEthSignedMessage, } from '@aztec/circuit-types'; @@ -37,7 +37,7 @@ export const mockAttestation = ( const header = makeHeader(1, 2, slot); const payload = new ConsensusPayload(header, archive, txs); - const hash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeperator.blockAttestation); + const hash = getHashedSignaturePayloadEthSignedMessage(payload, SignatureDomainSeparator.blockAttestation); const signature = signer.sign(hash); return new BlockAttestation(payload, signature); diff --git a/yarn-project/prover-client/src/block_builder/light.ts b/yarn-project/prover-client/src/block_builder/light.ts index e56986b839a..39d5b7a2185 100644 --- a/yarn-project/prover-client/src/block_builder/light.ts +++ b/yarn-project/prover-client/src/block_builder/light.ts @@ -4,6 +4,7 @@ import { MerkleTreeId, type MerkleTreeWriteOperations, type ProcessedTx, + TxHash, makeEmptyProcessedTx, toNumBlobFields, } from '@aztec/circuit-types'; @@ -53,7 +54,7 @@ export class LightweightBlockBuilder implements BlockBuilder { this.numTxs = Math.max(2, txs.length); this.spongeBlobState = SpongeBlob.init(toNumBlobFields(txs)); for (const tx of txs) { - this.logger.debug(tx.hash.isZero() ? 'Adding padding tx to block' : 'Adding new tx to block', { + this.logger.debug(tx.hash.equals(TxHash.zero()) ? 'Adding padding tx to block' : 'Adding new tx to block', { txHash: tx.hash.toString(), }); this.txs.push(tx); diff --git a/yarn-project/pxe/src/database/incoming_note_dao.ts b/yarn-project/pxe/src/database/incoming_note_dao.ts index d4c4192c3a5..93464386ec9 100644 --- a/yarn-project/pxe/src/database/incoming_note_dao.ts +++ b/yarn-project/pxe/src/database/incoming_note_dao.ts @@ -76,7 +76,7 @@ export class IncomingNoteDao implements NoteData { this.contractAddress, this.storageSlot, this.noteTypeId, - this.txHash.buffer, + this.txHash, this.l2BlockNumber, Fr.fromHexString(this.l2BlockHash), this.nonce, diff --git a/yarn-project/pxe/src/database/outgoing_note_dao.ts b/yarn-project/pxe/src/database/outgoing_note_dao.ts index 211c66cea7b..50fae33c524 100644 --- a/yarn-project/pxe/src/database/outgoing_note_dao.ts +++ b/yarn-project/pxe/src/database/outgoing_note_dao.ts @@ -69,7 +69,7 @@ export class OutgoingNoteDao { this.contractAddress, this.storageSlot, this.noteTypeId, - this.txHash.buffer, + this.txHash, this.l2BlockNumber, Fr.fromHexString(this.l2BlockHash), this.nonce, @@ -85,7 +85,7 @@ export class OutgoingNoteDao { const contractAddress = AztecAddress.fromBuffer(reader); const storageSlot = Fr.fromBuffer(reader); const noteTypeId = reader.readObject(NoteSelector); - const txHash = new TxHash(reader.readBytes(TxHash.SIZE)); + const txHash = reader.readObject(TxHash); const l2BlockNumber = reader.readNumber(); const l2BlockHash = Fr.fromBuffer(reader).toString(); const nonce = Fr.fromBuffer(reader); diff --git a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts index c27d4710031..1b5926e365a 100644 --- a/yarn-project/sequencer-client/src/publisher/l1-publisher.ts +++ b/yarn-project/sequencer-client/src/publisher/l1-publisher.ts @@ -3,7 +3,7 @@ import { type EpochProofClaim, type EpochProofQuote, type L2Block, - SignatureDomainSeperator, + SignatureDomainSeparator, type TxHash, getHashedSignaturePayload, } from '@aztec/circuit-types'; @@ -593,7 +593,7 @@ export class L1Publisher { const consensusPayload = new ConsensusPayload(block.header, block.archive.root, txHashes ?? []); - const digest = getHashedSignaturePayload(consensusPayload, SignatureDomainSeperator.blockAttestation); + const digest = getHashedSignaturePayload(consensusPayload, SignatureDomainSeparator.blockAttestation); const proposeTxArgs = { header: block.header.toBuffer(), archive: block.archive.root.toBuffer(), diff --git a/yarn-project/simulator/src/avm/fixtures/index.ts b/yarn-project/simulator/src/avm/fixtures/index.ts index fce5fb7eff4..7990a0b2c3b 100644 --- a/yarn-project/simulator/src/avm/fixtures/index.ts +++ b/yarn-project/simulator/src/avm/fixtures/index.ts @@ -55,7 +55,7 @@ export function initPersistableStateManager(overrides?: { overrides?.nullifiers || new NullifierManager(worldStateDB), overrides?.doMerkleOperations || false, overrides?.merkleTrees || mock(), - overrides?.txHash || new TxHash(new Fr(27).toBuffer()), + overrides?.txHash || new TxHash(new Fr(27)), ); } diff --git a/yarn-project/simulator/src/public/public_tx_context.ts b/yarn-project/simulator/src/public/public_tx_context.ts index 62dab19d16e..0c376934a20 100644 --- a/yarn-project/simulator/src/public/public_tx_context.ts +++ b/yarn-project/simulator/src/public/public_tx_context.ts @@ -459,5 +459,5 @@ function fetchTxHash(nonRevertibleAccumulatedData: PrivateToPublicAccumulatedDat if (!firstNullifier || firstNullifier.isZero()) { throw new Error(`Cannot get tx hash since first nullifier is missing`); } - return new TxHash(firstNullifier.toBuffer()); + return new TxHash(firstNullifier); } diff --git a/yarn-project/txe/src/index.ts b/yarn-project/txe/src/index.ts index 47079c7f6a5..9ba2b8d7b5c 100644 --- a/yarn-project/txe/src/index.ts +++ b/yarn-project/txe/src/index.ts @@ -109,7 +109,7 @@ class TXEDispatcher { } } -const TXEDispatcherApiChema: ApiSchemaFor = { +const TXEDispatcherApiSchema: ApiSchemaFor = { // eslint-disable-next-line camelcase resolve_foreign_call: z.function().args(TXEForeignCallInputSchema).returns(ForeignCallResultSchema), }; @@ -120,5 +120,5 @@ const TXEDispatcherApiChema: ApiSchemaFor = { * @returns A TXE RPC server. */ export function createTXERpcServer(logger: Logger) { - return createSafeJsonRpcServer(new TXEDispatcher(logger), TXEDispatcherApiChema); + return createSafeJsonRpcServer(new TXEDispatcher(logger), TXEDispatcherApiSchema); } diff --git a/yarn-project/txe/src/node/txe_node.ts b/yarn-project/txe/src/node/txe_node.ts index a5c8570be2f..8a5bbe90def 100644 --- a/yarn-project/txe/src/node/txe_node.ts +++ b/yarn-project/txe/src/node/txe_node.ts @@ -149,7 +149,7 @@ export class TXENode implements AztecNode { const tag = log.fields[0]; const currentLogs = this.#logsByTags.get(tag.toString()) ?? []; const scopedLog = new TxScopedL2Log( - new TxHash(new Fr(blockNumber).toBuffer()), + new TxHash(new Fr(blockNumber)), this.#noteIndex, blockNumber, false, @@ -193,7 +193,7 @@ export class TXENode implements AztecNode { const currentLogs = this.#logsByTags.get(tag.toString()) ?? []; const scopedLog = new TxScopedL2Log( - new TxHash(new Fr(blockNumber).toBuffer()), + new TxHash(new Fr(blockNumber)), this.#noteIndex, blockNumber, true, diff --git a/yarn-project/txe/src/oracle/txe_oracle.ts b/yarn-project/txe/src/oracle/txe_oracle.ts index ec4c7818525..608263ea150 100644 --- a/yarn-project/txe/src/oracle/txe_oracle.ts +++ b/yarn-project/txe/src/oracle/txe_oracle.ts @@ -649,7 +649,7 @@ export class TXE implements TypedOracle { // index = await (await this.trees.getLatest()).findLeafIndex(MerkleTreeId.NULLIFIER_TREE, Fr.random().toBuffer()); // console.log('INDEX OF RANDOM', index); - this.node.setTxEffect(blockNumber, new TxHash(new Fr(blockNumber).toBuffer()), txEffect); + this.node.setTxEffect(blockNumber, new TxHash(new Fr(blockNumber)), txEffect); this.node.setNullifiersIndexesWithBlock(blockNumber, txEffect.nullifiers); this.node.addNoteLogsByTags(this.blockNumber, this.privateLogs); this.node.addPublicLogsByTags(this.blockNumber, this.publicLogs); diff --git a/yarn-project/validator-client/src/duties/validation_service.ts b/yarn-project/validator-client/src/duties/validation_service.ts index e79fe5fa8c1..0772063a1f3 100644 --- a/yarn-project/validator-client/src/duties/validation_service.ts +++ b/yarn-project/validator-client/src/duties/validation_service.ts @@ -2,7 +2,7 @@ import { BlockAttestation, BlockProposal, ConsensusPayload, - SignatureDomainSeperator, + SignatureDomainSeparator, type TxHash, } from '@aztec/circuit-types'; import { type BlockHeader } from '@aztec/circuits.js'; @@ -43,7 +43,7 @@ export class ValidationService { // TODO(https://github.com/AztecProtocol/aztec-packages/issues/7961): check that the current validator is correct const buf = Buffer32.fromBuffer( - keccak256(proposal.payload.getPayloadToSign(SignatureDomainSeperator.blockAttestation)), + keccak256(proposal.payload.getPayloadToSign(SignatureDomainSeparator.blockAttestation)), ); const sig = await this.keyStore.signMessage(buf); return new BlockAttestation(proposal.payload, sig);