Skip to content

Commit

Permalink
feat: Re-introduced Aztec CLI (#6734)
Browse files Browse the repository at this point in the history
This PR reintroduces the Aztec CLI for use against deployed
environments. It also contains deployment and other fixes for an initial
devnet.

---------

Co-authored-by: Alex Gherghisan <[email protected]>
Co-authored-by: Mitchell Tracy <[email protected]>
Co-authored-by: spypsy <[email protected]>
Co-authored-by: Santiago Palladino <[email protected]>
Co-authored-by: ludamad <[email protected]>
  • Loading branch information
6 people authored May 30, 2024
1 parent d5550c6 commit a120015
Show file tree
Hide file tree
Showing 84 changed files with 4,278 additions and 119 deletions.
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/
import { type Fr } from '@aztec/circuits.js';

export { AccountContract } from './contract.js';
export { AccountInterface, AuthWitnessProvider } from './interface.js';
export { type AccountContract } from './contract.js';
export { type AccountInterface, type AuthWitnessProvider } from './interface.js';
export * from './wallet.js';

/** A contract deployment salt. */
Expand Down
6 changes: 5 additions & 1 deletion yarn-project/aztec.js/src/account_manager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import { DeployAccountSentTx } from './deploy_account_sent_tx.js';
/**
* Options to deploy an account contract.
*/
export type DeployAccountOptions = Pick<DeployOptions, 'fee' | 'skipClassRegistration' | 'skipPublicDeployment'>;
export type DeployAccountOptions = Pick<
DeployOptions,
'fee' | 'skipClassRegistration' | 'skipPublicDeployment' | 'estimateGas'
>;

/**
* Manages a user account. Provides methods for calculating the account's address, deploying the account contract,
Expand Down Expand Up @@ -163,6 +166,7 @@ export class AccountManager {
skipInitialization: false,
universalDeploy: true,
fee: opts?.fee,
estimateGas: opts?.estimateGas,
}),
)
.then(tx => tx.getTxHash());
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/api/abi.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { ContractArtifact, FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
export { type ContractArtifact, type FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
export { loadContractArtifact, contractArtifactToBuffer, contractArtifactFromBuffer } from '@aztec/types/abi';
export { NoirCompiledContract } from '@aztec/types/noir';
export { type NoirCompiledContract } from '@aztec/types/noir';
1 change: 1 addition & 0 deletions yarn-project/aztec.js/src/api/fee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { NativeFeePaymentMethod } from '../fee/native_fee_payment_method.js';
export { PrivateFeePaymentMethod } from '../fee/private_fee_payment_method.js';
export { PublicFeePaymentMethod } from '../fee/public_fee_payment_method.js';
export { NativeFeePaymentMethodWithClaim } from '../fee/native_fee_payment_method_with_claim.js';
export { NoFeePaymentMethod } from '../fee/no_fee_payment_method.js';
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Tx, type TxExecutionRequest } from '@aztec/circuit-types';
import { GasSettings } from '@aztec/circuits.js';
import { createDebugLogger } from '@aztec/foundation/log';

import { type Wallet } from '../account/wallet.js';
import { type ExecutionRequestInit, type FeeOptions } from '../entrypoint/entrypoint.js';
Expand Down Expand Up @@ -27,6 +28,8 @@ export abstract class BaseContractInteraction {
protected tx?: Tx;
protected txRequest?: TxExecutionRequest;

protected log = createDebugLogger('aztec:js:contract_interaction');

constructor(protected wallet: Wallet) {}

/**
Expand Down Expand Up @@ -104,6 +107,9 @@ export abstract class BaseContractInteraction {
simulationResult,
fee.gasSettings.teardownGasLimits,
);
this.log.debug(
`Estimated gas limits for tx: DA=${gasLimits.daGas} L2=${gasLimits.l2Gas} teardownDA=${teardownGasLimits.daGas} teardownL2=${teardownGasLimits.l2Gas}`,
);
const gasSettings = GasSettings.default({ ...fee.gasSettings, gasLimits, teardownGasLimits });
return { ...fee, gasSettings };
}
Expand Down
9 changes: 6 additions & 3 deletions yarn-project/aztec.js/src/contract/deploy_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from '@aztec/circuits.js';
import { type ContractArtifact, type FunctionArtifact, getInitializer } from '@aztec/foundation/abi';
import { type Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
import { type ContractInstanceWithAddress } from '@aztec/types/contracts';

import { type Wallet } from '../account/index.js';
Expand Down Expand Up @@ -53,8 +52,6 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
/** Cached call to request() */
private functionCalls?: ExecutionRequestInit;

private log = createDebugLogger('aztec:js:deploy_method');

constructor(
private publicKeysHash: Fr,
wallet: Wallet,
Expand Down Expand Up @@ -119,6 +116,12 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
};

if (options.estimateGas) {
// Why do we call this seemingly idempotent getter method here, without using its return value?
// This call pushes a capsule required for contract class registration under the hood. And since
// capsules are a stack, when we run the simulation for estimating gas, we consume the capsule
// that was meant for the actual call. So we need to push it again here. Hopefully this design
// will go away soon.
await this.getDeploymentFunctionCalls(options);
request.fee = await this.getFeeOptionsFromEstimatedGas(request);
}

Expand Down
23 changes: 23 additions & 0 deletions yarn-project/aztec.js/src/fee/no_fee_payment_method.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { type FunctionCall } from '@aztec/circuit-types';
import { AztecAddress } from '@aztec/circuits.js';

import { type FeePaymentMethod } from './fee_payment_method.js';

/**
* Does not pay fees. Will work until we enforce fee payment for all txs.
*/
export class NoFeePaymentMethod implements FeePaymentMethod {
constructor() {}

getAsset() {
return AztecAddress.ZERO;
}

getFunctionCalls(): Promise<FunctionCall[]> {
return Promise.resolve([]);
}

getFeePayer(): Promise<AztecAddress> {
return Promise.resolve(AztecAddress.ZERO);
}
}
9 changes: 5 additions & 4 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ export {
Contract,
ContractBase,
ContractFunctionInteraction,
ContractMethod,
ContractNotes,
ContractStorageLayout,
type ContractMethod,
type ContractNotes,
type ContractStorageLayout,
DeployMethod,
DeploySentTx,
type SendMethodOptions,
SentTx,
WaitOpts,
type WaitOpts,
} from './contract/index.js';

export { ContractDeployer } from './deployment/index.js';
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec/src/bin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ async function main() {

main().catch(err => {
debugLogger.error(`Error in command execution`);
debugLogger.error(err);
debugLogger.error(err + '\n' + err.stack);
process.exit(1);
});
24 changes: 15 additions & 9 deletions yarn-project/aztec/src/cli/cmds/start_prover.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { type ProvingJobSource } from '@aztec/circuit-types';
import { type ProverClientConfig, getProverEnvVars } from '@aztec/prover-client';
import { ProverPool, createProvingJobSourceClient } from '@aztec/prover-client/prover-pool';

import { tmpdir } from 'node:os';

import { type ServiceStarter, parseModuleOptions } from '../util.js';

type ProverOptions = Partial<{
proverUrl: string;
agents: string;
acvmBinaryPath?: string;
bbBinaryPath?: string;
simulate?: string;
}>;
type ProverOptions = ProverClientConfig &
Partial<{
proverUrl: string;
agents: string;
acvmBinaryPath?: string;
bbBinaryPath?: string;
simulate?: string;
}>;

export const startProver: ServiceStarter = async (options, signalHandlers, logger) => {
const proverOptions: ProverOptions = parseModuleOptions(options.prover);
const proverOptions: ProverOptions = {
proverUrl: process.env.PROVER_URL,
...getProverEnvVars(),
...parseModuleOptions(options.prover),
};
let source: ProvingJobSource;

if (typeof proverOptions.proverUrl === 'string') {
Expand All @@ -24,7 +30,7 @@ export const startProver: ServiceStarter = async (options, signalHandlers, logge
throw new Error('Starting prover without an orchestrator is not supported');
}

const agentCount = proverOptions.agents ? parseInt(proverOptions.agents, 10) : 1;
const agentCount = proverOptions.agents ? parseInt(proverOptions.agents, 10) : proverOptions.proverAgents;
if (agentCount === 0 || !Number.isSafeInteger(agentCount)) {
throw new Error('Cannot start prover without agents');
}
Expand Down
4 changes: 3 additions & 1 deletion yarn-project/aztec/src/cli/texts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ const contractAddresses =
'registryAddress:REGISTRY_CONTRACT_ADDRESS - string - The deployed L1 registry contract address.\n' +
'inboxAddress:INBOX_CONTRACT_ADDRESS - string - The deployed L1 inbox contract address.\n' +
'outboxAddress:OUTBOX_CONTRACT_ADDRESS - string - The deployed L1 outbox contract address.\n' +
'availabilityOracleAddress:AVAILABILITY_ORACLE_CONTRACT_ADDRESS - string - The deployed L1 availability oracle contract address.\n';
'availabilityOracleAddress:AVAILABILITY_ORACLE_CONTRACT_ADDRESS - string - The deployed L1 availability oracle contract address.\n' +
'gasTokenAddress:GAS_TOKEN_CONTRACT_ADDRESS - string - The deployed L1 gas token contract address.\n' +
'gasPortalAddress:GAS_PORTAL_CONTRACT_ADDRESS - string - The deployed L1 gas portal contract address.\n';
const p2pOptions =
'p2pBlockCheckIntervalMS:P2P_BLOCK_CHECK_INTERVAL_MS - number - The frequency in which to check for blocks. Default: 100\n' +
'p2pPeerCheckIntervalMS:P2P_PEER_CHECK_INTERVAL_MS - number - The frequency in which to check for peers. Default: 1000\n' +
Expand Down
Loading

0 comments on commit a120015

Please sign in to comment.