Skip to content

Commit

Permalink
chore: Refactor serialisation functions and sibling paths (#3980)
Browse files Browse the repository at this point in the history
This PR moves some serialisation functions from circuits.js to
foundation and sibling path to types.
  • Loading branch information
PhilWindle authored Jan 12, 2024
1 parent 0f994d0 commit 1a936fc
Show file tree
Hide file tree
Showing 119 changed files with 268 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
CallContext,
CompleteAddress,
ContractDeploymentData,
FieldsOf,
FunctionData,
L1_TO_L2_MSG_TREE_HEIGHT,
MAX_NEW_COMMITMENTS_PER_CALL,
Expand All @@ -29,6 +28,7 @@ import { pedersenHash } from '@aztec/foundation/crypto';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { FieldsOf } from '@aztec/foundation/types';
import { AppendOnlyTree, Pedersen, StandardTree, newTree } from '@aztec/merkle-tree';
import {
ChildContractArtifact,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/archiver/src/archiver/eth_log_handlers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
BufferReader,
CancelledL1ToL2Message,
ContractData,
EncodedContractFunction,
Expand All @@ -13,6 +12,7 @@ import {
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr, Point } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { ContractDeploymentEmitterAbi, InboxAbi, RollupAbi } from '@aztec/l1-artifacts';

import { Hex, Log, PublicClient, decodeFunctionData, getAbiItem, getAddress, hexToBytes } from 'viem';
Expand Down
1 change: 1 addition & 0 deletions yarn-project/aztec-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@aztec/merkle-tree": "workspace:^",
"@aztec/p2p": "workspace:^",
"@aztec/sequencer-client": "workspace:^",
"@aztec/types": "workspace:^",
"@aztec/world-state": "workspace:^",
"koa": "^2.14.2",
"koa-router": "^12.0.0",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/src/aztec-node/http_rpc_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
L2BlockL2Logs,
L2Tx,
LogId,
SiblingPath,
Tx,
TxHash,
} from '@aztec/circuit-types';
Expand All @@ -17,6 +16,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { JsonRpcServer } from '@aztec/foundation/json-rpc/server';
import { SiblingPath } from '@aztec/types/membership';

/**
* Wrap an AztecNode instance with a JSON RPC HTTP server.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
NullifierMembershipWitness,
PublicDataWitness,
SequencerConfig,
SiblingPath,
Tx,
TxHash,
} from '@aztec/circuit-types';
Expand Down Expand Up @@ -48,6 +47,7 @@ import {
SequencerClient,
getGlobalVariableBuilder,
} from '@aztec/sequencer-client';
import { SiblingPath } from '@aztec/types/membership';
import {
MerkleTrees,
ServerWorldStateSynchronizer,
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/aztec-node/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
{
"path": "../sequencer-client"
},
{
"path": "../types"
},
{
"path": "../world-state"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TxHash, TxReceipt } from '@aztec/circuit-types';
import { FieldsOf } from '@aztec/circuits.js';
import { FieldsOf } from '@aztec/foundation/types';

import { Wallet } from '../account/index.js';
import { DefaultWaitOpts, SentTx, WaitOpts } from '../contract/index.js';
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/aztec.js/src/contract/deploy_sent_tx.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PXE, TxHash, TxReceipt } from '@aztec/circuit-types';
import { AztecAddress, CompleteAddress, FieldsOf } from '@aztec/circuits.js';
import { AztecAddress, CompleteAddress } from '@aztec/circuits.js';
import { FieldsOf } from '@aztec/foundation/types';

import { Wallet } from '../account/index.js';
import { type Contract } from './contract.js';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/contract/sent_tx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ExtendedNote, GetUnencryptedLogsResponse, PXE, TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types';
import { FieldsOf } from '@aztec/circuits.js';
import { retryUntil } from '@aztec/foundation/retry';
import { FieldsOf } from '@aztec/foundation/types';

/** Options related to waiting for a tx. */
export type WaitOpts = {
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/auth_witness.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Vector } from '@aztec/circuits.js';
import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

/**
* An authentication witness. Used to authorize an action by a user.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { createJsonRpcClient, defaultFetch } from '@aztec/foundation/json-rpc/client';
import { SiblingPath } from '@aztec/types/membership';

import { ContractData, ExtendedContractData } from '../../contract_data.js';
import { AztecNode } from '../../interfaces/index.js';
import { L1ToL2MessageAndIndex } from '../../l1_to_l2_message.js';
import { L2Block } from '../../l2_block.js';
import { L2Tx } from '../../l2_tx.js';
import { ExtendedUnencryptedL2Log, L2BlockL2Logs, LogId } from '../../logs/index.js';
import { SiblingPath } from '../../sibling_path.js';
import { Tx, TxHash } from '../../tx/index.js';

/**
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/circuit-types/src/contract_dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
getFunctionDebugMetadata,
} from '@aztec/foundation/abi';
import { EthAddress } from '@aztec/foundation/eth-address';
import { prefixBufferWithLength } from '@aztec/foundation/serialize';
import { BufferReader, prefixBufferWithLength } from '@aztec/foundation/serialize';

import { BufferReader, EncodedContractFunction } from './contract_data.js';
import { EncodedContractFunction } from './contract_data.js';

/**
* A contract Data Access Object (DAO).
Expand Down
10 changes: 6 additions & 4 deletions yarn-project/circuit-types/src/contract_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
Point,
PublicKey,
} from '@aztec/circuits.js';
import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { randomBytes } from '@aztec/foundation/crypto';
import { EthAddress } from '@aztec/foundation/eth-address';
import { numToInt32BE, serializeBufferArrayToVector } from '@aztec/foundation/serialize';

export { BufferReader } from '@aztec/circuits.js/utils';
import {
BufferReader,
numToInt32BE,
serializeBufferArrayToVector,
serializeToBuffer,
} from '@aztec/foundation/serialize';

/**
* Used for retrieval of contract data (A3 address, portal contract address, bytecode).
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuit-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export * from './tx/index.js';
export * from './tx_execution_request.js';
export * from './packed_arguments.js';
export * from './interfaces/index.js';
export * from './sibling_path.js';
export * from './auth_witness.js';
export * from './aztec_node/rpc/index.js';
export { CompleteAddress, PublicKey, PartialAddress, GrumpkinPrivateKey } from '@aztec/circuits.js';
1 change: 0 additions & 1 deletion yarn-project/circuit-types/src/interfaces/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './state_info_provider.js';
export * from './hasher.js';
export * from './aztec-node.js';
export * from './pxe.js';
export * from './deployed-contract.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuit-types/src/interfaces/nullifier_tree.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Fr, NULLIFIER_TREE_HEIGHT, NullifierLeafPreimage } from '@aztec/circuits.js';

import { SiblingPath } from '../sibling_path.js';
import { SiblingPath } from '@aztec/types/membership';

/**
* Nullifier membership witness.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Fr, PUBLIC_DATA_TREE_HEIGHT, PublicDataTreeLeafPreimage } from '@aztec/circuits.js';

import { SiblingPath } from '../sibling_path.js';
import { SiblingPath } from '@aztec/types/membership';

/**
* Public data witness.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {
NULLIFIER_TREE_HEIGHT,
PUBLIC_DATA_TREE_HEIGHT,
} from '@aztec/circuits.js';
import { SiblingPath } from '@aztec/types/membership';

import { L1ToL2MessageAndIndex } from '../l1_to_l2_message.js';
import { L2Block } from '../l2_block.js';
import { MerkleTreeId } from '../merkle_tree_id.js';
import { SiblingPath } from '../sibling_path.js';
import { NullifierMembershipWitness } from './nullifier_tree.js';
import { PublicDataWitness } from './public_data_tree.js';

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/l1_to_l2_message.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { toBigIntBE, toBufferBE } from '@aztec/foundation/bigint-buffer';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

/**
* Interface of classes allowing for the retrieval of L1 to L2 messages.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuit-types/src/l2_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
StateReference,
} from '@aztec/circuits.js';
import { makeAppendOnlyTreeSnapshot, makeGlobalVariables, makeHeader } from '@aztec/circuits.js/factories';
import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
import { keccak, sha256 } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import times from 'lodash.times';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AztecAddress, GrumpkinPrivateKey, PublicKey } from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { serializeToBuffer } from '@aztec/circuits.js/utils';
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { decryptBuffer, encryptBuffer } from './encrypt_buffer.js';
import { Note } from './note.js';
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/circuit-types/src/packed_arguments.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FieldsOf, Fr, Vector } from '@aztec/circuits.js';
import { Fr, Vector } from '@aztec/circuits.js';
import { computeVarArgsHash } from '@aztec/circuits.js/abis';
import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

/**
* Packs a set of arguments into a hash.
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuit-types/src/public_data_write.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { STRING_ENCODING } from '@aztec/circuits.js';
import { serializeToBuffer } from '@aztec/circuits.js/utils';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

/**
* Write operations on the public state tree.
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuit-types/src/tx/tx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { MAX_NEW_CONTRACTS_PER_TX, PrivateKernelPublicInputsFinal, Proof, PublicCallRequest } from '@aztec/circuits.js';
import { serializeToBuffer } from '@aztec/circuits.js/utils';
import { arrayNonEmptyLength } from '@aztec/foundation/collection';
import { BufferReader, Tuple } from '@aztec/foundation/serialize';
import { BufferReader, Tuple, serializeToBuffer } from '@aztec/foundation/serialize';

import { ExtendedContractData } from '../contract_data.js';
import { GetUnencryptedLogsResponse } from '../logs/get_unencrypted_logs_response.js';
Expand Down
5 changes: 3 additions & 2 deletions yarn-project/circuit-types/src/tx_execution_request.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AztecAddress, FieldsOf, Fr, FunctionData, TxContext, TxRequest, Vector } from '@aztec/circuits.js';
import { BufferReader, serializeToBuffer } from '@aztec/circuits.js/utils';
import { AztecAddress, Fr, FunctionData, TxContext, TxRequest, Vector } from '@aztec/circuits.js';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import { AuthWitness } from './auth_witness.js';
import { PackedArguments } from './packed_arguments.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/abis/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AztecAddress } from '@aztec/foundation/aztec-address';
import { padArrayEnd } from '@aztec/foundation/collection';
import { keccak, pedersenHash, pedersenHashBuffer } from '@aztec/foundation/crypto';
import { Fr } from '@aztec/foundation/fields';
import { numToUInt8, numToUInt16BE, numToUInt32BE } from '@aztec/foundation/serialize';
import { boolToBuffer, numToUInt8, numToUInt16BE, numToUInt32BE } from '@aztec/foundation/serialize';

import { Buffer } from 'buffer';
import chunk from 'lodash.chunk';
Expand Down Expand Up @@ -35,7 +35,6 @@ import {
VerificationKey,
} from '../structs/index.js';
import { PublicKey } from '../types/index.js';
import { boolToBuffer } from '../utils/serialize.js';
import { MerkleTreeCalculator } from './merkle_tree_calculator.js';

/**
Expand Down
1 change: 0 additions & 1 deletion yarn-project/circuits.js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './structs/index.js';
export * from './utils/jsUtils.js';
export * from './contract/index.js';
export * from './types/index.js';
export * from './constants.gen.js';
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/structs/aggregation_object.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Fq, Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import times from 'lodash.times';

import { serializeToBuffer } from '../utils/serialize.js';
import { UInt32, Vector } from './shared.js';
import { G1AffineElement } from './verification_key.js';

Expand Down
5 changes: 2 additions & 3 deletions yarn-project/circuits.js/src/structs/call_context.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import { FieldsOf } from '../utils/jsUtils.js';
import { serializeToBuffer } from '../utils/serialize.js';
import { Fr, FunctionSelector } from './index.js';

/**
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/circuits.js/src/structs/call_request.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import { serializeToBuffer } from '../utils/serialize.js';

/**
* Caller context.
*/
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/structs/call_stack_item.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { computePrivateCallStackItemHash, computePublicCallStackItemHash } from '../abis/abis.js';
import { serializeToBuffer } from '../utils/serialize.js';
import { CallRequest, CallerContext } from './call_request.js';
import { FunctionData } from './function_data.js';
import { PrivateCircuitPublicInputs } from './private_circuit_public_inputs.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/structs/function_data.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { FunctionAbi, FunctionSelector, FunctionType } from '@aztec/foundation/abi';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { ContractFunctionDao } from '../index.js';
import { serializeToBuffer } from '../utils/serialize.js';

/**
* Function description for circuit.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { FunctionSelector } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';

import { serializeToBuffer } from '../utils/serialize.js';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

/**
* A class representing the "preimage" of a function tree leaf.
Expand Down
4 changes: 1 addition & 3 deletions yarn-project/circuits.js/src/structs/global_variables.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

import { serializeToBuffer } from '../utils/index.js';

/**
* Global variables of the L2 block.
*/
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuits.js/src/structs/header.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';

import { NUM_FIELDS_PER_SHA256 } from '../constants.gen.js';
import { serializeToBuffer } from '../utils/serialize.js';
import { GlobalVariables } from './global_variables.js';
import { AppendOnlyTreeSnapshot } from './rollup/append_only_tree_snapshot.js';
import { StateReference } from './state_reference.js';
Expand Down
6 changes: 2 additions & 4 deletions yarn-project/circuits.js/src/structs/kernel/block_header.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { Fr } from '@aztec/foundation/fields';
import { BufferReader } from '@aztec/foundation/serialize';

import { FieldsOf } from '../../utils/jsUtils.js';
import { serializeToBuffer } from '../../utils/serialize.js';
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
import { FieldsOf } from '@aztec/foundation/types';

/**
* The string encoding used for serializing BlockHeader objects.
Expand Down
Loading

0 comments on commit 1a936fc

Please sign in to comment.