Skip to content

Commit

Permalink
refactor: moving types consts to constants.nr (#4919)
Browse files Browse the repository at this point in the history
I need to access `INITIAL_L2_BLOCK_NUM` in the new Inbox contract so I
decided to move the constant to constants.nr so that the value gets
generated in ConstantsGen.sol.
  • Loading branch information
benesjan authored Mar 4, 2024
1 parent d98db3a commit ecfcb78
Show file tree
Hide file tree
Showing 24 changed files with 44 additions and 63 deletions.
8 changes: 4 additions & 4 deletions l1-contracts/slither_output.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,15 +288,15 @@ src/core/messagebridge/Inbox.sol#L148-L153
Impact: Informational
Confidence: Medium
- [ ] ID-31
Variable [Constants.LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP](src/core/libraries/ConstantsGen.sol#L127) is too similar to [Constants.NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP](src/core/libraries/ConstantsGen.sol#L120)
Variable [Constants.LOGS_HASHES_NUM_BYTES_PER_BASE_ROLLUP](src/core/libraries/ConstantsGen.sol#L129) is too similar to [Constants.NOTE_HASHES_NUM_BYTES_PER_BASE_ROLLUP](src/core/libraries/ConstantsGen.sol#L122)

src/core/libraries/ConstantsGen.sol#L127
src/core/libraries/ConstantsGen.sol#L129


- [ ] ID-32
Variable [Constants.L1_TO_L2_MESSAGE_LENGTH](src/core/libraries/ConstantsGen.sol#L107) is too similar to [Constants.L2_TO_L1_MESSAGE_LENGTH](src/core/libraries/ConstantsGen.sol#L108)
Variable [Constants.L1_TO_L2_MESSAGE_LENGTH](src/core/libraries/ConstantsGen.sol#L109) is too similar to [Constants.L2_TO_L1_MESSAGE_LENGTH](src/core/libraries/ConstantsGen.sol#L110)

src/core/libraries/ConstantsGen.sol#L107
src/core/libraries/ConstantsGen.sol#L109


- [ ] ID-33
Expand Down
2 changes: 2 additions & 0 deletions l1-contracts/src/core/libraries/ConstantsGen.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ library Constants {
uint256 internal constant NUM_FIELDS_PER_SHA256 = 2;
uint256 internal constant ARGS_HASH_CHUNK_LENGTH = 32;
uint256 internal constant ARGS_HASH_CHUNK_COUNT = 32;
uint256 internal constant INITIAL_L2_BLOCK_NUM = 1;
uint256 internal constant BLOB_SIZE_IN_BYTES = 126976;
uint256 internal constant MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 8000;
uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 500;
uint256 internal constant MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 500;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ global ARGS_HASH_CHUNK_COUNT: u64 = 32;
// The initialization slot is computed by adding the constant bellow to the variable's storage slot. This constant has
// to be large enough so that it's ensured that it doesn't collide with storage slots of other variables.
global INITIALIZATION_SLOT_SEPARATOR: Field = 1000_000_000;
global INITIAL_L2_BLOCK_NUM: Field = 1;
// 126976 = 31 * 4096;
global BLOB_SIZE_IN_BYTES: Field = 126976;

// CONTRACT CLASS CONSTANTS
global MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS: u64 = 8000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
ExtendedContractData,
INITIAL_L2_BLOCK_NUM,
L1ToL2Message,
L2Block,
L2BlockContext,
Expand All @@ -10,7 +9,7 @@ import {
UnencryptedL2Log,
} from '@aztec/circuit-types';
import '@aztec/circuit-types/jest';
import { AztecAddress, Fr } from '@aztec/circuits.js';
import { AztecAddress, Fr, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
import { makeContractClassPublic } from '@aztec/circuits.js/testing';
import { randomBytes } from '@aztec/foundation/crypto';
import { ContractClassPublic, ContractInstanceWithAddress, SerializableContractInstance } from '@aztec/types/contracts';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INITIAL_L2_BLOCK_NUM, L2Block, TxEffect, TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types';
import { AppendOnlyTreeSnapshot, AztecAddress, Header } from '@aztec/circuits.js';
import { L2Block, TxEffect, TxHash, TxReceipt, TxStatus } from '@aztec/circuit-types';
import { AppendOnlyTreeSnapshot, AztecAddress, Header, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
import { createDebugLogger } from '@aztec/foundation/log';
import { AztecKVStore, AztecMap, Range } from '@aztec/kv-store';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
ExtendedUnencryptedL2Log,
GetUnencryptedLogsResponse,
INITIAL_L2_BLOCK_NUM,
L2BlockL2Logs,
LogFilter,
LogId,
LogType,
UnencryptedL2Log,
} from '@aztec/circuit-types';
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
import { createDebugLogger } from '@aztec/foundation/log';
import { AztecKVStore, AztecMap } from '@aztec/kv-store';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
ExtendedContractData,
ExtendedUnencryptedL2Log,
GetUnencryptedLogsResponse,
INITIAL_L2_BLOCK_NUM,
L1ToL2Message,
L2Block,
L2BlockContext,
Expand All @@ -18,7 +17,7 @@ import {
TxStatus,
UnencryptedL2Log,
} from '@aztec/circuit-types';
import { Fr, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
import { Fr, INITIAL_L2_BLOCK_NUM, NUMBER_OF_L1_L2_MESSAGES_PER_ROLLUP } from '@aztec/circuits.js';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { ContractClassPublic, ContractInstanceWithAddress } from '@aztec/types/contracts';

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 @@ -5,7 +5,6 @@ import {
ContractDataSource,
ExtendedContractData,
GetUnencryptedLogsResponse,
INITIAL_L2_BLOCK_NUM,
L1ToL2MessageAndIndex,
L1ToL2MessageSource,
L2Block,
Expand All @@ -31,6 +30,7 @@ import {
EthAddress,
Fr,
Header,
INITIAL_L2_BLOCK_NUM,
L1_TO_L2_MSG_TREE_HEIGHT,
NOTE_HASH_TREE_HEIGHT,
NULLIFIER_TREE_HEIGHT,
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export {
Point,
getContractInstanceFromDeployParams,
getContractClassFromArtifact,
INITIAL_L2_BLOCK_NUM,
} from '@aztec/circuits.js';

export { computeMessageSecretHash } from '@aztec/circuits.js/hash';
Expand All @@ -88,7 +89,6 @@ export {
ExtendedNote,
FunctionCall,
GrumpkinPrivateKey,
INITIAL_L2_BLOCK_NUM,
L1ToL2Message,
L1Actor,
L2Actor,
Expand Down
2 changes: 0 additions & 2 deletions yarn-project/circuit-types/src/constants.ts

This file was deleted.

1 change: 0 additions & 1 deletion yarn-project/circuit-types/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './constants.js';
export * from './contract_dao.js';
export * from './contract_database.js';
export * from './contract_data.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
import { MemoryFifo, Semaphore, SerialQueue } from '@aztec/foundation/fifo';
import { createDebugLogger } from '@aztec/foundation/log';
import { InterruptibleSleep } from '@aztec/foundation/sleep';

import { INITIAL_L2_BLOCK_NUM } from '../constants.js';
import { L2Block } from '../l2_block.js';
import { L2BlockSource } from '../l2_block_source.js';

Expand Down
3 changes: 1 addition & 2 deletions yarn-project/circuit-types/src/logs/log_id.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
import { toBufferBE } from '@aztec/foundation/bigint-buffer';
import { BufferReader } from '@aztec/foundation/serialize';

import { INITIAL_L2_BLOCK_NUM } from '../constants.js';

/** A globally unique log id. */
export class LogId {
/**
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/circuits.js/src/constants.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export const FUNCTION_SELECTOR_NUM_BYTES = 4;
export const NUM_FIELDS_PER_SHA256 = 2;
export const ARGS_HASH_CHUNK_LENGTH = 32;
export const ARGS_HASH_CHUNK_COUNT = 32;
export const INITIAL_L2_BLOCK_NUM = 1;
export const BLOB_SIZE_IN_BYTES = 126976;
export const MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS = 8000;
export const MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS = 500;
export const MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS = 500;
Expand Down
11 changes: 2 additions & 9 deletions yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import {
INITIAL_L2_BLOCK_NUM,
L2Block,
L2BlockContext,
L2BlockDownloader,
L2BlockSource,
Tx,
TxHash,
} from '@aztec/circuit-types';
import { L2Block, L2BlockContext, L2BlockDownloader, L2BlockSource, Tx, TxHash } from '@aztec/circuit-types';
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
import { createDebugLogger } from '@aztec/foundation/log';
import { AztecKVStore, AztecSingleton } from '@aztec/kv-store';

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/pxe/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuit-types';
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';

import { readFileSync } from 'fs';
import { dirname, resolve } from 'path';
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/database/pxe_database_test_suite.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { INITIAL_L2_BLOCK_NUM, NoteFilter, NoteStatus, randomTxHash } from '@aztec/circuit-types';
import { AztecAddress, CompleteAddress } from '@aztec/circuits.js';
import { NoteFilter, NoteStatus, randomTxHash } from '@aztec/circuit-types';
import { AztecAddress, CompleteAddress, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
import { makeHeader } from '@aztec/circuits.js/testing';
import { Fr, Point } from '@aztec/foundation/fields';
import { BenchmarkingContractArtifact } from '@aztec/noir-contracts.js/Benchmarking';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/pxe/src/note_processor/note_processor.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
AztecNode,
FunctionL2Logs,
INITIAL_L2_BLOCK_NUM,
KeyPair,
KeyStore,
L1NotePayload,
Expand All @@ -12,7 +11,7 @@ import {
TaggedNote,
TxL2Logs,
} from '@aztec/circuit-types';
import { Fr, MAX_NEW_NOTE_HASHES_PER_TX } from '@aztec/circuits.js';
import { Fr, INITIAL_L2_BLOCK_NUM, MAX_NEW_NOTE_HASHES_PER_TX } from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { pedersenHash } from '@aztec/foundation/crypto';
import { Point } from '@aztec/foundation/fields';
Expand Down
12 changes: 2 additions & 10 deletions yarn-project/pxe/src/note_processor/note_processor.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
AztecNode,
INITIAL_L2_BLOCK_NUM,
KeyStore,
L1NotePayload,
L2BlockContext,
L2BlockL2Logs,
TaggedNote,
} from '@aztec/circuit-types';
import { AztecNode, KeyStore, L1NotePayload, L2BlockContext, L2BlockL2Logs, TaggedNote } from '@aztec/circuit-types';
import { NoteProcessorStats } from '@aztec/circuit-types/stats';
import { MAX_NEW_NOTE_HASHES_PER_TX, PublicKey } from '@aztec/circuits.js';
import { INITIAL_L2_BLOCK_NUM, MAX_NEW_NOTE_HASHES_PER_TX, PublicKey } from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
Expand Down
3 changes: 2 additions & 1 deletion yarn-project/pxe/src/pxe_service/test/pxe_service.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AztecNode, INITIAL_L2_BLOCK_NUM, PXE, TxEffect, mockTx } from '@aztec/circuit-types';
import { AztecNode, PXE, TxEffect, mockTx } from '@aztec/circuit-types';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js/constants';
import { L1ContractAddresses } from '@aztec/ethereum';
import { EthAddress } from '@aztec/foundation/eth-address';
import { TestKeyStore } from '@aztec/key-store';
Expand Down
14 changes: 8 additions & 6 deletions yarn-project/pxe/src/pxe_service/test/pxe_test_suite.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { DeployedContract, PXE, TxExecutionRequest, randomDeployedContract } from '@aztec/circuit-types';
import {
DeployedContract,
AztecAddress,
CompleteAddress,
Fr,
FunctionData,
INITIAL_L2_BLOCK_NUM,
PXE,
TxExecutionRequest,
randomDeployedContract,
} from '@aztec/circuit-types';
import { AztecAddress, CompleteAddress, Fr, FunctionData, Point, TxContext } from '@aztec/circuits.js';
Point,
TxContext,
} from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { ConstantKeyPair } from '@aztec/key-store';

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/synchronizer/synchronizer.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AztecNode, INITIAL_L2_BLOCK_NUM, L2Block } from '@aztec/circuit-types';
import { CompleteAddress, Fr, GrumpkinScalar, Header } from '@aztec/circuits.js';
import { AztecNode, L2Block } from '@aztec/circuit-types';
import { CompleteAddress, Fr, GrumpkinScalar, Header, INITIAL_L2_BLOCK_NUM } from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { makeHeader } from '@aztec/circuits.js/testing';
import { SerialQueue } from '@aztec/foundation/fifo';
Expand Down
12 changes: 2 additions & 10 deletions yarn-project/pxe/src/synchronizer/synchronizer.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {
AztecNode,
INITIAL_L2_BLOCK_NUM,
KeyStore,
L2BlockContext,
L2BlockL2Logs,
MerkleTreeId,
TxHash,
} from '@aztec/circuit-types';
import { AztecNode, KeyStore, L2BlockContext, L2BlockL2Logs, MerkleTreeId, TxHash } from '@aztec/circuit-types';
import { NoteProcessorCaughtUpStats } from '@aztec/circuit-types/stats';
import { AztecAddress, Fr, PublicKey } from '@aztec/circuits.js';
import { AztecAddress, Fr, INITIAL_L2_BLOCK_NUM, PublicKey } from '@aztec/circuits.js';
import { SerialQueue } from '@aztec/foundation/fifo';
import { DebugLogger, createDebugLogger } from '@aztec/foundation/log';
import { RunningPromise } from '@aztec/foundation/running-promise';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BLOB_SIZE_IN_BYTES, ExtendedContractData, L2Block } from '@aztec/circuit-types';
import { ExtendedContractData, L2Block } from '@aztec/circuit-types';
import { BLOB_SIZE_IN_BYTES } from '@aztec/circuits.js/constants';
import { createEthereumChain } from '@aztec/ethereum';
import { createDebugLogger } from '@aztec/foundation/log';
import { AvailabilityOracleAbi, ContractDeploymentEmitterAbi, RollupAbi } from '@aztec/l1-artifacts';
Expand Down

0 comments on commit ecfcb78

Please sign in to comment.