Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 10, 2023
1 parent b685510 commit 863ba94
Show file tree
Hide file tree
Showing 26 changed files with 2,086 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ describe('Private Execution test suite', () => {
);
});

it('should have an abi for computing note hash and nullifier', async () => {
it('should have an artifact for computing note hash and nullifier', async () => {
const storageSlot = Fr.random();
const note = buildNote(60n, owner, storageSlot);

Expand Down Expand Up @@ -416,7 +416,7 @@ describe('Private Execution test suite', () => {
);
});

it('should have an abi for computing note hash and nullifier', async () => {
it('should have an artifact for computing note hash and nullifier', async () => {
const storageSlot = Fr.random();
const note = buildNote(60n, owner, storageSlot);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const SECONDARY_AMOUNT = 33n;
/**
* Deploys the Private Token contract.
* @param owner - The address that the initial balance will belong to.
* @returns An Aztec Contract object with the private token's ABI.
* @returns An Aztec Contract object with the private token's artifact.
*/
async function deployZKContract(owner: AztecAddress) {
logger('Deploying L2 contract...');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContractArtifact } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
import { AuthWitness, CompleteAddress } from '@aztec/types';

import EcdsaAccountContractArtifact from '../../abis/ecdsa_account_contract.json' assert { type: 'json' };
import EcdsaAccountContractArtifact from '../../artifacts/ecdsa_account_contract.json' assert { type: 'json' };
import { AuthWitnessProvider } from '../interface.js';
import { BaseAccountContract } from './base_account_contract.js';

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/account/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ export * from './base_account_contract.js';

// docs:start:account-contract-interface
/**
* An account contract instance. Knows its ABI, deployment arguments, how to create
* An account contract instance. Knows its artifact, deployment arguments, how to create
* transaction execution requests out of function calls, and how to authorize actions.
*/
export interface AccountContract {
/**
* Returns the ABI of this account contract.
* Returns the artifact of this account contract.
*/
getContractArtifact(): ContractArtifact;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ContractArtifact } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';

import SchnorrAccountContractArtifact from '../../abis/schnorr_account_contract.json' assert { type: 'json' };
import SchnorrAccountContractArtifact from '../../artifacts/schnorr_account_contract.json' assert { type: 'json' };
import { AuthWitnessProvider } from '../interface.js';
import { BaseAccountContract } from './base_account_contract.js';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ContractArtifact } from '@aztec/foundation/abi';
import { Fr } from '@aztec/foundation/fields';
import { AuthWitness, CompleteAddress, GrumpkinPrivateKey } from '@aztec/types';

import SchnorrSingleKeyAccountContractArtifact from '../../abis/schnorr_single_key_account_contract.json' assert { type: 'json' };
import SchnorrSingleKeyAccountContractArtifact from '../../artifacts/schnorr_single_key_account_contract.json' assert { type: 'json' };
import { generatePublicKey } from '../../index.js';
import { AuthWitnessProvider } from '../interface.js';
import { BaseAccountContract } from './base_account_contract.js';
Expand Down
698 changes: 698 additions & 0 deletions yarn-project/aztec.js/src/artifacts/ecdsa_account_contract.json

Large diffs are not rendered by default.

686 changes: 686 additions & 0 deletions yarn-project/aztec.js/src/artifacts/schnorr_account_contract.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions yarn-project/aztec.js/src/contract/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ export function abiChecker(artifact: ContractArtifact) {

artifact.functions.forEach(func => {
if (!('name' in func && typeof func.name === 'string' && func.name.length > 0)) {
throw new Error('artifact function has no name');
throw new Error('ABI function has no name');
}

// TODO: implement a better check for bytecode (right now only checks if it's > 0)
if (!('bytecode' in func && typeof func.bytecode === 'string' && func.bytecode.length > 0)) {
throw new Error('artifact function parameter has incorrect bytecode');
throw new Error('ABI function parameter has incorrect bytecode');
}

func.parameters.forEach(param => {
if (!param.type) {
throw new Error('artifact function parameter has no type');
throw new Error('ABI function parameter has no type');
}

abiParameterTypeChecker(param.type);
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/aztec.js/src/contract_deployer/deploy_method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
public completeAddress?: CompleteAddress = undefined;

/** Constructor function to call. */
private constructorAbi: FunctionArtifact;
private constructorArtifact: FunctionArtifact;

constructor(
private publicKey: PublicKey,
Expand All @@ -49,7 +49,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
super(pxe);
const constructorArtifact = artifact.functions.find(f => f.name === 'constructor');
if (!constructorArtifact) throw new Error('Cannot find constructor in the artifact.');
this.constructorAbi = constructorArtifact;
this.constructorArtifact = constructorArtifact;
}

/**
Expand Down Expand Up @@ -90,8 +90,8 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
new Fr(chainId),
new Fr(protocolVersion),
);
const args = encodeArguments(this.constructorAbi, this.args);
const functionData = FunctionData.fromAbi(this.constructorAbi);
const args = encodeArguments(this.constructorArtifact, this.args);
const functionData = FunctionData.fromAbi(this.constructorArtifact);
const execution = { args, functionData, to: completeAddress.address };
const packedArguments = await PackedArguments.fromArgs(execution.args);

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/src/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sleep } from '@aztec/foundation/sleep';

import zip from 'lodash.zip';

import SchnorrAccountContractArtifact from '../abis/schnorr_account_contract.json' assert { type: 'json' };
import SchnorrAccountContractArtifact from '../artifacts/schnorr_account_contract.json' assert { type: 'json' };
import { AccountWalletWithPrivateKey, PXE, createPXEClient, getSchnorrAccount } from '../index.js';

export const INITIAL_SANDBOX_ENCRYPTION_KEYS = [
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/boxes/blank-react/src/artifacts/blank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class BlankContract extends ContractBase {
* @returns A promise that resolves to a new Contract instance.
*/
public static async at(address: AztecAddress, wallet: Wallet) {
return Contract.at(address, BlankContract.abi, wallet) as Promise<BlankContract>;
return Contract.at(address, BlankContract.artifact, wallet) as Promise<BlankContract>;
}

/**
Expand All @@ -54,9 +54,9 @@ export class BlankContract extends ContractBase {
}

/**
* Returns this contract's ABI.
* Returns this contract's artifact.
*/
public static get abi(): ContractArtifact {
public static get artifact(): ContractArtifact {
return BlankContractArtifact;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const setupSandbox = async () => {

async function deployZKContract(owner: CompleteAddress, wallet: Wallet, pxe: PXE) {
logger('Deploying Blank contract...');
const contractAddress = await deployContract(owner, BlankContract.abi, [], Fr.random(), pxe);
const contractAddress = await deployContract(owner, BlankContract.artifact, [], Fr.random(), pxe);

logger(`L2 contract deployed at ${contractAddress}`);
return BlankContract.at(contractAddress, wallet);
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/boxes/blank/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ The `src/artifacts` folder can be re-generated from the command line
yarn compile
```

This will generate a [Contract ABI](src/artifacts/test_contract.json) and TypeScript class for the [Aztec smart contract](src/contracts/main.nr), which the frontend uses to generate the UI.
This will generate a [contract artifact](src/artifacts/test_contract.json) and TypeScript class for the [Aztec smart contract](src/contracts/main.nr), which the frontend uses to generate the UI.

Note: the `compile` command seems to generate a Typescript file which needs a single change -

Expand All @@ -63,7 +63,7 @@ import TestContractArtifactJson from 'text_contract.json' assert { type: 'json'
import TestContractArtifactJson from './test_contract.json' assert { type: 'json' };
```

After compiling, you can re-deploy the upated noir smart contract from the web UI. The function interaction forms are generated from parsing the ContractABI, so they should update automatically after you recompile.
After compiling, you can re-deploy the updated noir smart contract from the web UI. The function interaction forms are generated from parsing the contract artifact, so they should update automatically after you recompile.

## Learn More

Expand Down
4 changes: 2 additions & 2 deletions yarn-project/boxes/private-token/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ Most relevant to you is likely `src/contracts/main.nr` (and the build config `sr

The `src/artifacts` folder can be re-generated from the command line with `yarn compile`.

This will generate a [Contract ABI](src/artifacts/test_contract.json) and TypeScript class for the Aztec smart contract in `src/contracts/main.nr`, which the frontend uses to generate the UI.
This will generate a [contract artifact](src/artifacts/test_contract.json) and TypeScript class for the Aztec smart contract in `src/contracts/main.nr`, which the frontend uses to generate the UI.

After compiling, you can re-deploy the upated noir smart contract from the web UI. The function interaction forms are generated from parsing the ContractABI, so they should update automatically after you recompile.
After compiling, you can re-deploy the updated noir smart contract from the web UI. The function interaction forms are generated from parsing the contract artifact, so they should update automatically after you recompile.

## Learn More

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class PrivateTokenContract extends ContractBase {
* @returns A promise that resolves to a new Contract instance.
*/
public static async at(address: AztecAddress, wallet: Wallet) {
return Contract.at(address, PrivateTokenContract.abi, wallet) as Promise<PrivateTokenContract>;
return Contract.at(address, PrivateTokenContract.artifact, wallet) as Promise<PrivateTokenContract>;
}

/**
Expand Down Expand Up @@ -64,9 +64,9 @@ export class PrivateTokenContract extends ContractBase {
}

/**
* Returns this contract's ABI.
* Returns this contract's artifact.
*/
public static get abi(): ContractArtifact {
public static get artifact(): ContractArtifact {
return PrivateTokenContractArtifact;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async function deployZKContract(owner: CompleteAddress, wallet: Wallet, pxe: PXE
logger('Deploying PrivateToken contract...');
const typedArgs = [new Fr(INITIAL_BALANCE), owner.address.toField()];

const contractAddress = await deployContract(owner, PrivateTokenContract.abi, typedArgs, Fr.random(), pxe);
const contractAddress = await deployContract(owner, PrivateTokenContract.artifact, typedArgs, Fr.random(), pxe);

logger(`L2 contract deployed at ${contractAddress}`);
return PrivateTokenContract.at(contractAddress, wallet);
Expand Down
32 changes: 16 additions & 16 deletions yarn-project/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,22 +140,22 @@ Deploys a compiled Aztec.nr contract to Aztec.
Syntax:

```shell
aztec-cli deploy <contractAbi> [options]
aztec-cli deploy <contractArtifact> [options]
```

Options:

- `-c, --contract-artifact <fileLocation>`: Path to the compiled Aztec.nr contract's ABI file in JSON format. You can also use one of Aztec's example contracts found in [@aztec/noir-contracts](https://www.npmjs.com/package/@aztec/noir-contracts), e.g. PrivateTokenContractArtifact. You can get a full ist of the available contracts with `aztec-cli example-contracts`
- `-c, --contract-artifact <fileLocation>`: Path to the compiled Aztec.nr contract's artifact file in JSON format. You can also use one of Aztec's example contracts found in [@aztec/noir-contracts](https://www.npmjs.com/package/@aztec/noir-contracts), e.g. PrivateTokenContractArtifact. You can get a full ist of the available contracts with `aztec-cli example-contracts`
- `-a, --args <constructorArgs...>` (optional): Contract constructor arguments Default: [].
- `-u, --rpc-url <string>`: URL of PXE Service. Default: `http://localhost:8080`.
- `-k, --public-key <string>`: Public key of the deployer. If not provided, it will check the RPC for existing ones.

This command deploys a compiled Aztec.nr contract to Aztec. It requires the path to the contract's ABI file in JSON format. Optionally, you can specify the public key of the deployer and provide constructor arguments for the contract. The command displays the address of the deployed contract.
This command deploys a compiled Aztec.nr contract to Aztec. It requires the path to the contract's artifact file in JSON format. Optionally, you can specify the public key of the deployer and provide constructor arguments for the contract. The command displays the address of the deployed contract.

Example usage:

```shell
aztec-cli deploy -c path/to/contract.abi.json -a ...args
aztec-cli deploy -c path/to/contract.artifact.json -a ...args
```

With an Aztec example contract:
Expand Down Expand Up @@ -313,25 +313,25 @@ Sends a transaction invoking a function on an Aztec contract.
Syntax:

```shell
aztec-cli send <functionName> --args [functionArgs...] --contract-artifact <contractAbi> --contract-address <contractAddress> --private-key <senderPrivateKey>
aztec-cli send <functionName> --args [functionArgs...] --contract-artifact <contractArtifact> --contract-address <contractAddress> --private-key <senderPrivateKey>
```

- `functionName`: Name of the function to call.

Options:

- `'-a, --args [functionArgs...]` (optional): Function arguments. Default: [].
- `-c, --contract-artifact <fileLocation>`: The compiled contract's ABI in JSON format. You can also use one of Aztec's example contracts found in (@aztec/noir-contracts)[https://www.npmjs.com/package/@aztec/noir-contracts], e.g. PrivateTokenContractArtifact.
- `-c, --contract-artifact <fileLocation>`: The compiled contract's artifact in JSON format. You can also use one of Aztec's example contracts found in (@aztec/noir-contracts)[https://www.npmjs.com/package/@aztec/noir-contracts], e.g. PrivateTokenContractArtifact.
- `-ca, --contract-address <address>`: Address of the contract.
- `-k, --private-key <string>`: The sender's private key.
- `-u, --rpc-url <string>`: URL of PXE Service. Default: `http://localhost:8080`.

This command calls a function on an Aztec contract. It requires the contract's ABI, address, function name, and optionally, function arguments. The command executes the function call and displays the transaction details.
This command calls a function on an Aztec contract. It requires the contract's artifact, address, function name, and optionally, function arguments. The command executes the function call and displays the transaction details.

Example usage:

```shell
aztec-cli send transfer -ca 0x123456789abcdef123456789abcdef12345678 -a 100 -c path/to/abi.json
aztec-cli send transfer -ca 0x123456789abcdef123456789abcdef12345678 -a 100 -c path/to/artifact.json
```

### call
Expand All @@ -342,25 +342,25 @@ Unlike transactions, view calls do not modify the state of the contract.
Syntax:

```shell
aztec-cli call <functionName> -a [functionArgs...] -c <contractAbi> -ca <contractAddress> -f <fromAddress>
aztec-cli call <functionName> -a [functionArgs...] -c <contractArtifact> -ca <contractAddress> -f <fromAddress>
```

- `functionName`: Name of the function to view.

Options:

- `'-a, --args [functionArgs...]` (optional): Function arguments. Default: [].
- `-c, --contract-artifact <fileLocation>`: The compiled contract's ABI in JSON format. You can also use one of Aztec's example contracts found in (@aztec/noir-contracts)[https://www.npmjs.com/package/@aztec/noir-contracts], e.g. PrivateTokenContractArtifact.
- `-c, --contract-artifact <fileLocation>`: The compiled contract's artifact in JSON format. You can also use one of Aztec's example contracts found in (@aztec/noir-contracts)[https://www.npmjs.com/package/@aztec/noir-contracts], e.g. PrivateTokenContractArtifact.
- `-ca, --contract-address <address>`: Address of the contract.
- `-f, --from <string>`: Address of the caller. If empty, first account in the Private eXecution Environment (PXE) will be used.
- `-u, --rpc-url <string>`: URL of PXE Service. Default: `http://localhost:8080`.

This command simulates the execution of a view function on a deployed contract without modifying the state. It requires the contract's ABI, address, function name, and optionally, function arguments. The command displays the result of the view function.
This command simulates the execution of a view function on a deployed contract without modifying the state. It requires the contract's artifact, address, function name, and optionally, function arguments. The command displays the result of the view function.

Example usage:

```shell
aztec-cli call balanceOf -c path/to/contract.abi.json -ca 0x123456789abcdef123456789abcdef12345678 -a balanceOf 0xabcdef1234567890abcdef1234567890abcdef12
aztec-cli call balanceOf -c path/to/contract.artifact.json -ca 0x123456789abcdef123456789abcdef12345678 -a balanceOf 0xabcdef1234567890abcdef1234567890abcdef12
```

### parse-parameter-struct
Expand All @@ -370,19 +370,19 @@ Helper for parsing an encoded string into a contract's parameter struct.
Syntax:

```shell
aztec-cli parse-parameter-struct <encodedString> <contractAbi> <parameterName>
aztec-cli parse-parameter-struct <encodedString> <contractArtifact> <parameterName>
```

- `encodedString`: The encoded hex string.
- `contractAbi`: The compiled contract's ABI in JSON format.
- `contractArtifact`: The compiled contract's artifact in JSON format.
- `parameterName`: The name of the struct parameter to decode into.

This command is a helper for parsing an encoded hex string into a contract's parameter struct. It requires the encoded string, the contract's ABI, and the name of the struct parameter. The command decodes the string and displays the struct data.
This command is a helper for parsing an encoded hex string into a contract's parameter struct. It requires the encoded string, the contract's artifact, and the name of the struct parameter. The command decodes the string and displays the struct data.

Example usage:

```shell
aztec-cli parse-parameter-struct 0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890 path/to/contract.abi.json paramName
aztec-cli parse-parameter-struct 0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890 path/to/contract.artifact.json paramName
```

### get-logs
Expand Down
8 changes: 4 additions & 4 deletions yarn-project/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ export async function getTxSender(pxe: PXE, _from?: string) {
* @returns Formatted contract address, function arguments and caller's aztec address.
*/
export async function prepTx(contractFile: string, functionName: string, _functionArgs: string[], log: LogFn) {
const contractAbi = await getContractArtifact(contractFile, log);
const functionAbi = getFunctionArtifact(contractAbi, functionName);
const functionArgs = encodeArgs(_functionArgs, functionAbi.parameters);
const contractArtifact = await getContractArtifact(contractFile, log);
const functionArtifact = getFunctionArtifact(contractArtifact, functionName);
const functionArgs = encodeArgs(_functionArgs, functionArtifact.parameters);

return { functionArgs, contractAbi };
return { functionArgs, contractAbi: contractArtifact };
}

/**
Expand Down
Loading

0 comments on commit 863ba94

Please sign in to comment.