Skip to content

Commit

Permalink
Update yarn-project
Browse files Browse the repository at this point in the history
  • Loading branch information
spalladino committed Jan 15, 2024
1 parent b87561a commit 2914c3f
Show file tree
Hide file tree
Showing 52 changed files with 339 additions and 536 deletions.
2 changes: 1 addition & 1 deletion yarn-project/accounts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"scripts": {
"build": "yarn clean && yarn build:copy-contracts && tsc -b",
"build:copy-contracts": "mkdir -p ./src/artifacts && cp ../noir-contracts/src/SchnorrAccount.json ../noir-contracts/src/EcdsaAccount.json ../noir-contracts/src/SchnorrSingleKeyAccount.json ./src/artifacts",
"build:copy-contracts": "./scripts/copy-contracts.sh",
"build:dev": "tsc -b --watch",
"build:ts": "tsc -b",
"clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/accounts/package.local.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"scripts": {
"build": "yarn clean && yarn build:copy-contracts && tsc -b",
"build:copy-contracts": "mkdir -p ./src/artifacts && cp ../noir-contracts/src/SchnorrAccount.json ../noir-contracts/src/EcdsaAccount.json ../noir-contracts/src/SchnorrSingleKeyAccount.json ./src/artifacts",
"build:copy-contracts": "./scripts/copy-contracts.sh",
"build:dev": "tsc -b --watch",
"build:ts": "tsc -b",
"clean": "rm -rf ./dest .tsbuildinfo ./src/artifacts"
Expand Down
9 changes: 9 additions & 0 deletions yarn-project/accounts/scripts/copy-contracts.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash
set -euo pipefail
mkdir -p ./src/artifacts

contracts=(schnorr_account_contract-SchnorrAccount ecdsa_account_contract-EcdsaAccount schnorr_single_key_account_contract-SchnorrSingleKeyAccount)

for contract in "${contracts[@]}"; do
cp "../noir-contracts/target/$contract.json" ./src/artifacts/${contract#*-}.json
done
4 changes: 2 additions & 2 deletions yarn-project/accounts/src/ecdsa/artifact.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContractArtifact } from '@aztec/aztec.js';
import { NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js';

import EcdsaAccountContractJson from '../artifacts/EcdsaAccount.json' assert { type: 'json' };

export const EcdsaAccountContractArtifact = EcdsaAccountContractJson as ContractArtifact;
export const EcdsaAccountContractArtifact = loadContractArtifact(EcdsaAccountContractJson as NoirCompiledContract);
4 changes: 2 additions & 2 deletions yarn-project/accounts/src/schnorr/artifact.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ContractArtifact } from '@aztec/aztec.js';
import { NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js';

import SchnorrAccountContractJson from '../artifacts/SchnorrAccount.json' assert { type: 'json' };

export const SchnorrAccountContractArtifact = SchnorrAccountContractJson as ContractArtifact;
export const SchnorrAccountContractArtifact = loadContractArtifact(SchnorrAccountContractJson as NoirCompiledContract);
6 changes: 4 additions & 2 deletions yarn-project/accounts/src/single_key/artifact.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ContractArtifact } from '@aztec/aztec.js';
import { NoirCompiledContract, loadContractArtifact } from '@aztec/aztec.js';

import SchnorrSingleKeyAccountContractJson from '../artifacts/SchnorrSingleKeyAccount.json' assert { type: 'json' };

export const SchnorrSingleKeyAccountContractArtifact = SchnorrSingleKeyAccountContractJson as ContractArtifact;
export const SchnorrSingleKeyAccountContractArtifact = loadContractArtifact(
SchnorrSingleKeyAccountContractJson as NoirCompiledContract,
);
12 changes: 1 addition & 11 deletions yarn-project/acir-simulator/src/client/db_oracle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { L2Block, MerkleTreeId, NullifierMembershipWitness, PublicDataWitness } from '@aztec/circuit-types';
import { BlockHeader, CompleteAddress, GrumpkinPrivateKey, PublicKey } from '@aztec/circuits.js';
import { FunctionArtifact, FunctionDebugMetadata, FunctionSelector } from '@aztec/foundation/abi';
import { FunctionArtifactWithDebugMetadata, FunctionSelector } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
Expand All @@ -17,16 +17,6 @@ export class ContractNotFoundError extends Error {
}
}

/**
* A function artifact with optional debug metadata
*/
export interface FunctionArtifactWithDebugMetadata extends FunctionArtifact {
/**
* Debug metadata for the function.
*/
debug?: FunctionDebugMetadata;
}

/**
* The database oracle interface.
*/
Expand Down
10 changes: 8 additions & 2 deletions yarn-project/acir-simulator/src/client/private_execution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import {
siloCommitment,
} from '@aztec/circuits.js/abis';
import { makeContractDeploymentData } from '@aztec/circuits.js/factories';
import { FunctionArtifact, FunctionSelector, encodeArguments } from '@aztec/foundation/abi';
import {
FunctionArtifact,
FunctionSelector,
encodeArguments,
getFunctionArtifact,
getFunctionArtifactWithSelector,
} from '@aztec/foundation/abi';
import { asyncMap } from '@aztec/foundation/async-map';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { pedersenHash } from '@aztec/foundation/crypto';
Expand All @@ -46,7 +52,7 @@ import { default as levelup } from 'levelup';
import { type MemDown, default as memdown } from 'memdown';
import { getFunctionSelector } from 'viem';

import { buildL1ToL2Message, getFunctionArtifact, getFunctionArtifactWithSelector } from '../test/utils.js';
import { buildL1ToL2Message } from '../test/utils.js';
import { computeSlotForMapping } from '../utils.js';
import { DBOracle } from './db_oracle.js';
import { AcirSimulator } from './simulator.js';
Expand Down
3 changes: 1 addition & 2 deletions yarn-project/acir-simulator/src/client/private_execution.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionData, PrivateCallStackItem } from '@aztec/circuits.js';
import { decodeReturnValues } from '@aztec/foundation/abi';
import { FunctionArtifactWithDebugMetadata, decodeReturnValues } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
Expand All @@ -9,7 +9,6 @@ import { extractPrivateCircuitPublicInputs } from '../acvm/deserialize.js';
import { Oracle, acvm, extractCallStack } from '../acvm/index.js';
import { ExecutionError } from '../common/errors.js';
import { ClientExecutionContext } from './client_execution_context.js';
import { FunctionArtifactWithDebugMetadata } from './db_oracle.js';
import { ExecutionResult } from './execution_result.js';
import { AcirSimulator } from './simulator.js';

Expand Down
5 changes: 2 additions & 3 deletions yarn-project/acir-simulator/src/client/simulator.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Note } from '@aztec/circuit-types';
import { CompleteAddress } from '@aztec/circuits.js';
import { computeUniqueCommitment, siloCommitment } from '@aztec/circuits.js/abis';
import { ABIParameterVisibility } from '@aztec/foundation/abi';
import { ABIParameterVisibility, FunctionArtifactWithDebugMetadata, getFunctionArtifact } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { pedersenHash } from '@aztec/foundation/crypto';
import { Fr, GrumpkinScalar } from '@aztec/foundation/fields';
import { TokenContractArtifact } from '@aztec/noir-contracts/Token';

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

import { getFunctionArtifact } from '../test/utils.js';
import { DBOracle, FunctionArtifactWithDebugMetadata } from './db_oracle.js';
import { DBOracle } from './db_oracle.js';
import { AcirSimulator } from './simulator.js';

describe('Simulator', () => {
Expand Down
10 changes: 8 additions & 2 deletions yarn-project/acir-simulator/src/client/simulator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { AztecNode, FunctionCall, Note, TxExecutionRequest } from '@aztec/circuit-types';
import { CallContext, FunctionData } from '@aztec/circuits.js';
import { Grumpkin } from '@aztec/circuits.js/barretenberg';
import { ArrayType, FunctionSelector, FunctionType, encodeArguments } from '@aztec/foundation/abi';
import {
ArrayType,
FunctionArtifactWithDebugMetadata,
FunctionSelector,
FunctionType,
encodeArguments,
} from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { EthAddress } from '@aztec/foundation/eth-address';
import { Fr } from '@aztec/foundation/fields';
Expand All @@ -12,7 +18,7 @@ import { WasmBlackBoxFunctionSolver, createBlackBoxSolver } from '@noir-lang/acv
import { createSimulationError } from '../common/errors.js';
import { PackedArgsCache } from '../common/packed_args_cache.js';
import { ClientExecutionContext } from './client_execution_context.js';
import { DBOracle, FunctionArtifactWithDebugMetadata } from './db_oracle.js';
import { DBOracle } from './db_oracle.js';
import { ExecutionNoteCache } from './execution_note_cache.js';
import { ExecutionResult } from './execution_result.js';
import { executePrivateFunction } from './private_execution.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FunctionData } from '@aztec/circuits.js';
import { DecodedReturn, decodeReturnValues } from '@aztec/foundation/abi';
import { DecodedReturn, FunctionArtifactWithDebugMetadata, decodeReturnValues } from '@aztec/foundation/abi';
import { AztecAddress } from '@aztec/foundation/aztec-address';
import { Fr } from '@aztec/foundation/fields';
import { createDebugLogger } from '@aztec/foundation/log';
Expand All @@ -8,7 +8,6 @@ import { extractReturnWitness } from '../acvm/deserialize.js';
import { ACVMField, Oracle, acvm, extractCallStack, fromACVMField, toACVMWitness } from '../acvm/index.js';
import { ExecutionError } from '../common/errors.js';
import { AcirSimulator } from '../index.js';
import { FunctionArtifactWithDebugMetadata } from './db_oracle.js';
import { ViewDataOracle } from './view_data_oracle.js';

/**
Expand Down
31 changes: 0 additions & 31 deletions yarn-project/acir-simulator/src/test/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { L1Actor, L1ToL2Message, L2Actor } from '@aztec/circuit-types';
import { AztecAddress, EthAddress, Fr } from '@aztec/circuits.js';
import { computeSecretMessageHash } from '@aztec/circuits.js/abis';
import { ContractArtifact, FunctionSelector, getFunctionDebugMetadata } from '@aztec/foundation/abi';
import { sha256 } from '@aztec/foundation/crypto';

import { FunctionArtifactWithDebugMetadata } from '../index.js';

/**
* Test utility function to craft an L1 to L2 message.
* @param selector - The cross chain message selector.
Expand Down Expand Up @@ -39,31 +36,3 @@ export const buildL1ToL2Message = (
0,
);
};

export const getFunctionArtifact = (
artifact: ContractArtifact,
functionName: string,
): FunctionArtifactWithDebugMetadata => {
const functionArtifact = artifact.functions.find(f => f.name === functionName);
if (!functionArtifact) {
throw new Error(`Unknown function ${functionName}`);
}

const debug = getFunctionDebugMetadata(artifact, functionName);
return { ...functionArtifact, debug };
};

export const getFunctionArtifactWithSelector = (
artifact: ContractArtifact,
functionSelector: FunctionSelector,
): FunctionArtifactWithDebugMetadata => {
const functionArtifact = artifact.functions.find(f =>
functionSelector.equals(FunctionSelector.fromNameAndParameters(f.name, f.parameters)),
);
if (!functionArtifact) {
throw new Error(`Unknown function ${functionSelector}`);
}

const debug = getFunctionDebugMetadata(artifact, functionArtifact.name);
return { ...functionArtifact, debug };
};
3 changes: 1 addition & 2 deletions yarn-project/aztec.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"tsconfig": "./tsconfig.json"
},
"scripts": {
"build": "yarn clean && yarn build:copy-contracts && tsc -b && webpack",
"build:copy-contracts": "mkdir -p ./src/account_contract/artifacts && cp ../noir-contracts/src/SchnorrAccount.json ../noir-contracts/src/EcdsaAccount.json ../noir-contracts/src/SchnorrSingleKeyAccount.json ./src/account_contract/artifacts",
"build": "yarn clean && tsc -b && webpack",
"build:web": "webpack",
"build:dev": "tsc -b --watch",
"build:ts": "tsc -b",
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/aztec.js/package.local.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scripts": {
"build": "yarn clean && yarn build:copy-contracts && tsc -b && webpack",
"build": "yarn clean && tsc -b && webpack",
"build:web": "webpack",
"build:dev": "tsc -b --watch",
"build:ts": "tsc -b",
Expand Down
2 changes: 2 additions & 0 deletions yarn-project/aztec.js/src/api/abi.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export { ContractArtifact, FunctionArtifact, FunctionSelector } from '@aztec/foundation/abi';
export { loadContractArtifact } from '@aztec/types/abi';
export { NoirCompiledContract } from '@aztec/types/noir';
4 changes: 4 additions & 0 deletions yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ describe('Contract Class', () => {
name: 'bar',
functionType: FunctionType.SECRET,
isInternal: false,
debugSymbols: '',
parameters: [
{
name: 'value',
Expand All @@ -69,6 +70,7 @@ describe('Contract Class', () => {
parameters: [],
returnTypes: [],
bytecode: '0be',
debugSymbols: '',
},
{
name: 'qux',
Expand All @@ -91,9 +93,11 @@ describe('Contract Class', () => {
},
],
bytecode: '0cd',
debugSymbols: '',
},
],
events: [],
fileMap: {},
};

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ describe.skip('Contract Deployer', () => {
parameters: [],
returnTypes: [],
bytecode: '0af',
debugSymbols: '',
},
],
events: [],
fileMap: {},
};

const publicKey: PublicKey = Point.random();
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/aztec.js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ export {
EthAddress,
Fr,
Fq,
FunctionSelector,
GlobalVariables,
GrumpkinScalar,
Point,
Expand Down Expand Up @@ -114,7 +113,7 @@ export { NodeInfo } from '@aztec/types/interfaces';
// TODO: These kinds of things have no place on our public api.
// External devs will almost certainly have their own methods of doing these things.
// If we want to use them in our own "aztec.js consuming code", import them from foundation as needed.
export { ContractArtifact, FunctionArtifact, encodeArguments } from '@aztec/foundation/abi';
export { encodeArguments } from '@aztec/foundation/abi';
export { sha256 } from '@aztec/foundation/crypto';
export { DebugLogger, createDebugLogger, onLog } from '@aztec/foundation/log';
export { retry, retryUntil } from '@aztec/foundation/retry';
Expand All @@ -137,3 +136,4 @@ export {
// Here you *can* do `export *` as the granular api defacto exports things explicitly.
// This entire index file will be deprecated at some point after we're satisfied.
export * from './api/init.js';
export * from './api/abi.js';
2 changes: 2 additions & 0 deletions yarn-project/circuit-types/src/contract_dao.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ describe('ContractDao', () => {
],
returnTypes: [],
bytecode: '0af',
debugSymbols: '',
},
],
events: [],
fileMap: {},
};

const dao = new ContractDao(artifact, CompleteAddress.random(), EthAddress.random());
Expand Down
9 changes: 5 additions & 4 deletions yarn-project/circuit-types/src/contract_dao.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CompleteAddress, ContractFunctionDao } from '@aztec/circuits.js';
import {
ContractArtifact,
DebugMetadata,
DebugFileMap,
EventAbi,
FunctionDebugMetadata,
FunctionSelector,
Expand Down Expand Up @@ -46,8 +46,8 @@ export class ContractDao implements ContractArtifact {
return this.contractArtifact.events;
}

get debug(): DebugMetadata | undefined {
return this.contractArtifact.debug;
get fileMap(): DebugFileMap {
return this.contractArtifact.fileMap;
}

getFunctionArtifact(selector: FunctionSelector): ContractFunctionDao | undefined {
Expand All @@ -59,7 +59,8 @@ export class ContractDao implements ContractArtifact {
}

getFunctionDebugMetadataByName(functionName: string): FunctionDebugMetadata | undefined {
return getFunctionDebugMetadata(this, functionName);
const fn = this.getFunctionArtifactByName(functionName);
return fn && getFunctionDebugMetadata(this, fn);
}

toBuffer(): Buffer {
Expand Down
1 change: 1 addition & 0 deletions yarn-project/circuit-types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const randomContractArtifact = (): ContractArtifact => ({
name: randomBytes(4).toString('hex'),
functions: [],
events: [],
fileMap: {},
});

export const randomDeployedContract = (): DeployedContract => ({
Expand Down
3 changes: 3 additions & 0 deletions yarn-project/cli/src/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const mockContractArtifact: ContractArtifact = {
],
returnTypes: [],
bytecode: 'constructorBytecode',
debugSymbols: '',
},
{
name: 'mockFunction',
Expand Down Expand Up @@ -59,7 +60,9 @@ export const mockContractArtifact: ContractArtifact = {
],
returnTypes: [{ kind: 'boolean' }],
bytecode: 'mockBytecode',
debugSymbols: '',
},
],
events: [],
fileMap: {},
};
2 changes: 1 addition & 1 deletion yarn-project/end-to-end/tsconfig.web.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
{
"path": "../aztec.js"
}
],
]
}
Loading

0 comments on commit 2914c3f

Please sign in to comment.