Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .test_patterns.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ tests:
error_regex: "TimeoutError: Timeout awaiting isMined"
owners:
- *palla
- regex: "simple e2e_p2p/gossip_network"
error_regex: "TimeoutError: Timeout awaiting isMined"
owners:
- *palla
- regex: "simple e2e_fees/private_payments"
owners:
- *phil
Expand Down
30 changes: 29 additions & 1 deletion yarn-project/archiver/src/test/mock_l2_block_source.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { DefaultL1ContractsConfig } from '@aztec/ethereum';
import { Buffer32 } from '@aztec/foundation/buffer';
import { EthAddress } from '@aztec/foundation/eth-address';
import type { Fr } from '@aztec/foundation/fields';
import { createLogger } from '@aztec/foundation/log';
import type { FunctionSelector } from '@aztec/stdlib/abi';
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
import { L2Block, L2BlockHash, type L2BlockSource, type L2Tips } from '@aztec/stdlib/block';
import type { ContractClassPublic, ContractDataSource, ContractInstanceWithAddress } from '@aztec/stdlib/contract';
import { type L1RollupConstants, getSlotRangeForEpoch } from '@aztec/stdlib/epoch-helpers';
import { type BlockHeader, TxHash, TxReceipt, TxStatus } from '@aztec/stdlib/tx';

/**
* A mocked implementation of L2BlockSource to be used in tests.
*/
export class MockL2BlockSource implements L2BlockSource {
export class MockL2BlockSource implements L2BlockSource, ContractDataSource {
protected l2Blocks: L2Block[] = [];

private provenBlockNumber: number = 0;
Expand Down Expand Up @@ -221,4 +225,28 @@ export class MockL2BlockSource implements L2BlockSource {
this.log.verbose('Stopping mock L2 block source');
return Promise.resolve();
}

getContractClass(_id: Fr): Promise<ContractClassPublic | undefined> {
return Promise.resolve(undefined);
}

getBytecodeCommitment(_id: Fr): Promise<Fr | undefined> {
return Promise.resolve(undefined);
}

getContract(_address: AztecAddress, _blockNumber?: number): Promise<ContractInstanceWithAddress | undefined> {
return Promise.resolve(undefined);
}

getContractClassIds(): Promise<Fr[]> {
return Promise.resolve([]);
}

getDebugFunctionName(_address: AztecAddress, _selector: FunctionSelector): Promise<string | undefined> {
return Promise.resolve(undefined);
}

registerContractFunctionSignatures(_address: AztecAddress, _signatures: string[]): Promise<void> {
return Promise.resolve();
}
}
5 changes: 2 additions & 3 deletions yarn-project/aztec-node/src/aztec-node/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ import { openTmpStore } from '@aztec/kv-store/lmdb';
import { RollupAbi } from '@aztec/l1-artifacts';
import { SHA256Trunc, StandardTree, UnbalancedTree } from '@aztec/merkle-tree';
import { trySnapshotSync, uploadSnapshot } from '@aztec/node-lib/actions';
import { type P2P, createP2PClient } from '@aztec/p2p';
import { type P2P, createP2PClient, getDefaultAllowedSetupFunctions } from '@aztec/p2p';
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
import {
GlobalVariableBuilder,
SequencerClient,
type SequencerPublisher,
createSlasherClient,
createValidatorForAcceptingTxs,
getDefaultAllowedSetupFunctions,
} from '@aztec/sequencer-client';
import { PublicProcessorFactory } from '@aztec/simulator/server';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
Expand Down Expand Up @@ -989,7 +988,7 @@ export class AztecNodeService implements AztecNode, AztecNodeAdmin, Traceable {
blockNumber,
l1ChainId: this.l1ChainId,
rollupVersion: this.version,
setupAllowList: this.config.allowedInSetup ?? (await getDefaultAllowedSetupFunctions()),
setupAllowList: this.config.txPublicSetupAllowList ?? (await getDefaultAllowedSetupFunctions()),
gasFees: await this.getCurrentBaseFees(),
skipFeeEnforcement,
});
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/foundation/src/config/env_var.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ export type EnvVar =
| 'ROLLUP_CONTRACT_ADDRESS'
| 'SENTINEL_ENABLED'
| 'SENTINEL_HISTORY_LENGTH_IN_EPOCHS'
| 'SEQ_ALLOWED_SETUP_FN'
| 'SEQ_MAX_BLOCK_SIZE_IN_BYTES'
| 'SEQ_MAX_TX_PER_BLOCK'
| 'SEQ_MIN_TX_PER_BLOCK'
Expand All @@ -169,6 +168,7 @@ export type EnvVar =
| 'TEST_ACCOUNTS'
| 'SPONSORED_FPC'
| 'TX_GOSSIP_VERSION'
| 'TX_PUBLIC_SETUP_ALLOWLIST'
| 'TXE_PORT'
| 'VALIDATOR_ATTESTATIONS_POLLING_INTERVAL_MS'
| 'VALIDATOR_DISABLED'
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/p2p/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@
"@aztec/epoch-cache": "workspace:^",
"@aztec/foundation": "workspace:^",
"@aztec/kv-store": "workspace:^",
"@aztec/noir-contracts.js": "workspace:^",
"@aztec/noir-protocol-circuits-types": "workspace:^",
"@aztec/protocol-contracts": "workspace:^",
"@aztec/simulator": "workspace:^",
"@aztec/stdlib": "workspace:^",
"@aztec/telemetry-client": "workspace:^",
"@chainsafe/discv5": "9.0.0",
Expand Down
7 changes: 4 additions & 3 deletions yarn-project/p2p/src/client/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { AztecAsyncKVStore } from '@aztec/kv-store';
import type { DataStoreConfig } from '@aztec/kv-store/config';
import { createStore } from '@aztec/kv-store/lmdb-v2';
import type { L2BlockSource } from '@aztec/stdlib/block';
import type { ContractDataSource } from '@aztec/stdlib/contract';
import type { ClientProtocolCircuitVerifier, WorldStateSynchronizer } from '@aztec/stdlib/interfaces/server';
import { P2PClientType } from '@aztec/stdlib/p2p';
import { type TelemetryClient, getTelemetryClient } from '@aztec/telemetry-client';
Expand All @@ -29,7 +30,7 @@ type P2PClientDeps<T extends P2PClientType> = {
export const createP2PClient = async <T extends P2PClientType>(
clientType: T,
_config: P2PConfig & DataStoreConfig,
l2BlockSource: L2BlockSource,
archiver: L2BlockSource & ContractDataSource,
proofVerifier: ClientProtocolCircuitVerifier,
worldStateSynchronizer: WorldStateSynchronizer,
epochCache: EpochCacheInterface,
Expand Down Expand Up @@ -73,7 +74,7 @@ export const createP2PClient = async <T extends P2PClientType>(
discoveryService,
peerId,
mempools,
l2BlockSource,
archiver,
epochCache,
proofVerifier,
worldStateSynchronizer,
Expand All @@ -85,5 +86,5 @@ export const createP2PClient = async <T extends P2PClientType>(
logger.verbose('P2P is disabled. Using dummy P2P service');
p2pService = new DummyP2PService();
}
return new P2PClient(clientType, store, l2BlockSource, mempools, p2pService, config, telemetry);
return new P2PClient(clientType, store, archiver, mempools, p2pService, config, telemetry);
};
3 changes: 2 additions & 1 deletion yarn-project/p2p/src/client/p2p_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {
L2Tips,
PublishedL2Block,
} from '@aztec/stdlib/block';
import type { ContractDataSource } from '@aztec/stdlib/contract';
import type { P2PApi, PeerInfo, ProverCoordination } from '@aztec/stdlib/interfaces/server';
import { BlockAttestation, type BlockProposal, ConsensusPayload, type P2PClientType } from '@aztec/stdlib/p2p';
import type { Tx, TxHash } from '@aztec/stdlib/tx';
Expand Down Expand Up @@ -211,7 +212,7 @@ export class P2PClient<T extends P2PClientType = P2PClientType.Full>
constructor(
_clientType: T,
store: AztecAsyncKVStore,
private l2BlockSource: L2BlockSource,
private l2BlockSource: L2BlockSource & ContractDataSource,
mempools: MemPools<T>,
private p2pService: P2PService,
config: Partial<P2PConfig> = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import { Fr } from '@aztec/foundation/fields';
import { FunctionSelector } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';

import { parseSequencerAllowList } from './config.js';
import { parseAllowList } from './config.js';

describe('sequencer config', () => {
it('parse a sequencer config', async () => {
describe('config', () => {
it('parses allow list', async () => {
const instance = { address: await AztecAddress.random() };
const instanceFunction = { address: await AztecAddress.random(), selector: FunctionSelector.random() };
const classId = { classId: Fr.random() };
Expand All @@ -21,7 +21,7 @@ describe('sequencer config', () => {
];
const stringifiedAllowList = configStrings.join(',');

const allowList = parseSequencerAllowList(stringifiedAllowList);
const allowList = parseAllowList(stringifiedAllowList);
expect(allowList).toEqual(config);
});
});
65 changes: 64 additions & 1 deletion yarn-project/p2p/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import {
numberConfigHelper,
pickConfigMappings,
} from '@aztec/foundation/config';
import { Fr } from '@aztec/foundation/fields';
import { type DataStoreConfig, dataConfigMappings } from '@aztec/kv-store/config';
import { type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';
import { FunctionSelector } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { type AllowedElement, type ChainConfig, chainConfigMappings } from '@aztec/stdlib/config';

import { type P2PReqRespConfig, p2pReqRespConfigMappings } from './services/reqresp/config.js';

Expand Down Expand Up @@ -169,6 +172,9 @@ export interface P2PConfig extends P2PReqRespConfig, ChainConfig {
* The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKB.
*/
p2pStoreMapSizeKb?: number;

/** Which calls are allowed in the public setup phase of a tx. */
txPublicSetupAllowList: AllowedElement[];
}

export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
Expand Down Expand Up @@ -341,6 +347,13 @@ export const p2pConfigMappings: ConfigMappingsType<P2PConfig> = {
parseEnv: (val: string | undefined) => (val ? +val : undefined),
description: 'The maximum possible size of the P2P DB in KB. Overwrites the general dataStoreMapSizeKB.',
},
txPublicSetupAllowList: {
env: 'TX_PUBLIC_SETUP_ALLOWLIST',
parseEnv: (val: string) => parseAllowList(val),
description: 'The list of functions calls allowed to run in setup',
printDefault: () =>
'AuthRegistry, FeeJuice.increase_public_balance, Token.increase_public_balance, FPC.prepare_fee',
},
...p2pReqRespConfigMappings,
...chainConfigMappings,
};
Expand Down Expand Up @@ -383,3 +396,53 @@ export const bootnodeConfigMappings = pickConfigMappings(
{ ...p2pConfigMappings, ...dataConfigMappings, ...chainConfigMappings },
bootnodeConfigKeys,
);

/**
* Parses a string to a list of allowed elements.
* Each encoded is expected to be of one of the following formats
* `I:${address}`
* `I:${address}:${selector}`
* `C:${classId}`
* `C:${classId}:${selector}`
*
* @param value The string to parse
* @returns A list of allowed elements
*/
export function parseAllowList(value: string): AllowedElement[] {
const entries: AllowedElement[] = [];

if (!value) {
return entries;
}

for (const val of value.split(',')) {
const [typeString, identifierString, selectorString] = val.split(':');
const selector = selectorString !== undefined ? FunctionSelector.fromString(selectorString) : undefined;

if (typeString === 'I') {
if (selector) {
entries.push({
address: AztecAddress.fromString(identifierString),
selector,
});
} else {
entries.push({
address: AztecAddress.fromString(identifierString),
});
}
} else if (typeString === 'C') {
if (selector) {
entries.push({
classId: Fr.fromHexString(identifierString),
selector,
});
} else {
entries.push({
classId: Fr.fromHexString(identifierString),
});
}
}
}

return entries;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { getContractClassFromArtifact } from '@aztec/stdlib/contract';
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';

let defaultAllowedSetupFunctions: AllowedElement[] | undefined = undefined;

export async function getDefaultAllowedSetupFunctions(): Promise<AllowedElement[]> {
if (defaultAllowedSetupFunctions === undefined) {
defaultAllowedSetupFunctions = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import { FunctionSelector } from '@aztec/stdlib/abi';
import { AztecAddress } from '@aztec/stdlib/aztec-address';
import { GasFees, GasSettings } from '@aztec/stdlib/gas';
import { mockTx } from '@aztec/stdlib/testing';
import type { PublicStateSource } from '@aztec/stdlib/trees';
import type { Tx } from '@aztec/stdlib/tx';

import { type MockProxy, mock, mockFn } from 'jest-mock-extended';

import { GasTxValidator, type PublicStateSource } from './gas_validator.js';
import { GasTxValidator } from './gas_validator.js';
import { patchNonRevertibleFn, patchRevertibleFn } from './test_utils.js';

describe('GasTxValidator', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { Fr } from '@aztec/foundation/fields';
import { createLogger } from '@aztec/foundation/log';
import { computeFeePayerBalanceStorageSlot } from '@aztec/protocol-contracts/fee-juice';
import { getCallRequestsWithCalldataByPhase } from '@aztec/simulator/server';
import { FunctionSelector } from '@aztec/stdlib/abi';
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
import type { GasFees } from '@aztec/stdlib/gas';
import type { PublicStateSource } from '@aztec/stdlib/trees';
import { type Tx, TxExecutionPhase, type TxValidationResult, type TxValidator } from '@aztec/stdlib/tx';

/** Provides a view into public contract state */
export interface PublicStateSource {
storageRead: (contractAddress: AztecAddress, slot: Fr) => Promise<Fr>;
}

export class GasTxValidator implements TxValidator<Tx> {
#log = createLogger('sequencer:tx_validator:tx_gas');
#publicDataSource: PublicStateSource;
Expand Down
4 changes: 4 additions & 0 deletions yarn-project/p2p/src/msg_validators/tx_validator/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@ export * from './double_spend_validator.js';
export * from './metadata_validator.js';
export * from './tx_proof_validator.js';
export * from './block_header_validator.js';
export * from './gas_validator.js';
export * from './phases_validator.js';
export * from './test_utils.js';
export * from './allowed_public_setup.js';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PublicContractsDB, getCallRequestsWithCalldataByPhase } from '@aztec/si
import type { ContractDataSource } from '@aztec/stdlib/contract';
import type { AllowedElement } from '@aztec/stdlib/interfaces/server';
import {
PublicCallRequestWithCalldata,
type PublicCallRequestWithCalldata,
Tx,
TxExecutionPhase,
type TxValidationResult,
Expand Down
Loading