diff --git a/avm-transpiler/src/transpile_contract.rs b/avm-transpiler/src/transpile_contract.rs index 6f8922f8045a..f7b732df61db 100644 --- a/avm-transpiler/src/transpile_contract.rs +++ b/avm-transpiler/src/transpile_contract.rs @@ -16,7 +16,7 @@ pub struct TranspiledContract { pub name: String, // Functions can be ACIR or AVM pub functions: Vec, - pub events: serde_json::Value, + pub outputs: serde_json::Value, pub file_map: serde_json::Value, //pub warnings: serde_json::Value, } @@ -29,7 +29,7 @@ pub struct CompiledAcirContract { pub noir_version: String, pub name: String, pub functions: Vec, - pub events: serde_json::Value, + pub outputs: serde_json::Value, pub file_map: serde_json::Value, //pub warnings: serde_json::Value, } @@ -113,7 +113,7 @@ impl From for TranspiledContract { noir_version: contract.noir_version, name: contract.name, functions, // some acir, some transpiled avm functions - events: contract.events, + outputs: contract.outputs, file_map: contract.file_map, //warnings: contract.warnings, } diff --git a/noir/noir-repo/compiler/wasm/src/types/noir_artifact.ts b/noir/noir-repo/compiler/wasm/src/types/noir_artifact.ts index 935c99043daf..d4d05b79b494 100644 --- a/noir/noir-repo/compiler/wasm/src/types/noir_artifact.ts +++ b/noir/noir-repo/compiler/wasm/src/types/noir_artifact.ts @@ -1,35 +1,44 @@ import { Abi, AbiType } from '@noir-lang/types'; /** - * A named type. + * A basic value. */ -export interface ABIVariable { +export interface BasicValue { /** - * The name of the variable. + * The kind of the value. */ - name: string; - /** - * The type of the variable. - */ - type: AbiType; + kind: T; + value: V; +} + +/** + * An exported value. + */ +export type ABIValue = + | BasicValue<'field', bigint> + | BasicValue<'boolean', boolean> + | BasicValue<'integer', number> + | BasicValue<'string', string> + | BasicValue<'array', ABIValue[]> + | StructValue; + +export interface StructValue { + kind: 'struct'; + fields: (ABIValue & { name: string })[]; } /** - * A contract event. + * A named type. */ -export interface EventAbi { +export interface ABIVariable { /** - * The event name. + * The name of the variable. */ name: string; /** - * Fully qualified name of the event. - */ - path: string; - /** - * The fields of the event. + * The type of the variable. */ - fields: ABIVariable[]; + type: AbiType; } /** @@ -60,8 +69,11 @@ export interface ContractArtifact { noir_version: string; /** The functions of the contract. */ functions: NoirFunctionEntry[]; - /** The events of the contract */ - events: EventAbi[]; + + outputs: { + structs: Record; + globals: Record; + }; /** The map of file ID to the source code and path of the file. */ file_map: DebugFileMap; } diff --git a/noir/noir-repo/tooling/noirc_abi/src/lib.rs b/noir/noir-repo/tooling/noirc_abi/src/lib.rs index b73af1ccff88..c1fa4b9f2167 100644 --- a/noir/noir-repo/tooling/noirc_abi/src/lib.rs +++ b/noir/noir-repo/tooling/noirc_abi/src/lib.rs @@ -521,15 +521,18 @@ pub enum AbiValue { Field { value: FieldElement, }, - Array { - values: Vec, - }, Integer { value: i128, }, Boolean { value: bool, }, + String { + value: String, + }, + Array { + value: Vec, + }, Struct { #[serde( serialize_with = "serialization::serialize_struct_field_values", @@ -540,9 +543,6 @@ pub enum AbiValue { Tuple { fields: Vec, }, - String { - value: String, - }, } impl AbiValue { @@ -567,7 +567,7 @@ impl AbiValue { HirExpression::Literal(literal) => match literal { HirLiteral::Array(hir_array) => match hir_array { HirArrayLiteral::Standard(expr_ids) => { - let values = expr_ids + let value = expr_ids .iter() .map(|expr_id| { Self::from_hir_expression( @@ -576,7 +576,7 @@ impl AbiValue { ) }) .collect(); - Self::Array { values } + Self::Array { value } } _ => unreachable!("Repeated arrays cannot be used in the abi"), }, diff --git a/yarn-project/aztec.js/src/contract/contract.test.ts b/yarn-project/aztec.js/src/contract/contract.test.ts index 90e822a8f8e5..3d332775a638 100644 --- a/yarn-project/aztec.js/src/contract/contract.test.ts +++ b/yarn-project/aztec.js/src/contract/contract.test.ts @@ -100,7 +100,10 @@ describe('Contract Class', () => { debugSymbols: '', }, ], - events: [], + outputs: { + structs: {}, + globals: {}, + }, fileMap: {}, }; diff --git a/yarn-project/circuit-types/src/mocks.ts b/yarn-project/circuit-types/src/mocks.ts index 30ad57764ac9..37b807aff0df 100644 --- a/yarn-project/circuit-types/src/mocks.ts +++ b/yarn-project/circuit-types/src/mocks.ts @@ -56,7 +56,10 @@ export const mockTx = (seed = 1, logs = true) => { export const randomContractArtifact = (): ContractArtifact => ({ name: randomBytes(4).toString('hex'), functions: [], - events: [], + outputs: { + structs: {}, + globals: {}, + }, fileMap: {}, }); diff --git a/yarn-project/circuits.js/src/contract/artifact_hash.ts b/yarn-project/circuits.js/src/contract/artifact_hash.ts index a51a609ccfd4..4201f6f27141 100644 --- a/yarn-project/circuits.js/src/contract/artifact_hash.ts +++ b/yarn-project/circuits.js/src/contract/artifact_hash.ts @@ -43,7 +43,7 @@ export function computeArtifactHash(artifact: ContractArtifact): Fr { export function computeArtifactMetadataHash(artifact: ContractArtifact) { // TODO(@spalladino): Should we use the sorted event selectors instead? They'd need to be unique for that. - const metadata = { name: artifact.name, events: artifact.events }; + const metadata = { name: artifact.name, outputs: artifact.outputs }; return sha256(Buffer.from(JSON.stringify(metadata), 'utf-8')); } diff --git a/yarn-project/cli/src/test/mocks.ts b/yarn-project/cli/src/test/mocks.ts index b1463de3acd8..fc0a77366048 100644 --- a/yarn-project/cli/src/test/mocks.ts +++ b/yarn-project/cli/src/test/mocks.ts @@ -65,6 +65,9 @@ export const mockContractArtifact: ContractArtifact = { debugSymbols: '', }, ], - events: [], + outputs: { + structs: {}, + globals: {}, + }, fileMap: {}, }; diff --git a/yarn-project/foundation/src/abi/abi.ts b/yarn-project/foundation/src/abi/abi.ts index d8ba0f8a7e4f..b3218a24420b 100644 --- a/yarn-project/foundation/src/abi/abi.ts +++ b/yarn-project/foundation/src/abi/abi.ts @@ -2,6 +2,33 @@ import { inflate } from 'pako'; import { type FunctionSelector } from './function_selector.js'; +/** + * A basic value. + */ +export interface BasicValue { + /** + * The kind of the value. + */ + kind: T; + value: V; +} + +/** + * An exported value. + */ +export type ABIValue = + | BasicValue<'field', bigint> + | BasicValue<'boolean', boolean> + | BasicValue<'integer', number> + | BasicValue<'string', string> + | BasicValue<'array', ABIValue[]> + | StructValue; + +export interface StructValue { + kind: 'struct'; + fields: (ABIValue & { name: string })[]; +} + /** * A named type. */ @@ -101,24 +128,6 @@ export interface StructType extends BasicType<'struct'> { path: string; } -/** - * A contract event. - */ -export interface EventAbi { - /** - * The event name. - */ - name: string; - /** - * Fully qualified name of the event. - */ - path: string; - /** - * The fields of the event. - */ - fields: ABIVariable[]; -} - /** * Aztec.nr function types. */ @@ -258,7 +267,10 @@ export interface ContractArtifact { /** * The events of the contract. */ - events: EventAbi[]; + outputs: { + structs: Record; + globals: Record; + }; /** * The map of file ID to the source code and path of the file. diff --git a/yarn-project/types/src/abi/contract_artifact.ts b/yarn-project/types/src/abi/contract_artifact.ts index 04f820181948..cbbabe120f6d 100644 --- a/yarn-project/types/src/abi/contract_artifact.ts +++ b/yarn-project/types/src/abi/contract_artifact.ts @@ -174,7 +174,7 @@ function generateContractArtifact(contract: NoirCompiledContract, aztecNrVersion return { name: contract.name, functions: contract.functions.map(generateFunctionArtifact), - events: contract.events, + outputs: contract.outputs, fileMap: contract.file_map, aztecNrVersion, }; diff --git a/yarn-project/types/src/noir/index.ts b/yarn-project/types/src/noir/index.ts index 097129d74fb5..1de030e78df4 100644 --- a/yarn-project/types/src/noir/index.ts +++ b/yarn-project/types/src/noir/index.ts @@ -2,9 +2,9 @@ import { ABIParameter, ABIParameterVisibility, ABIType, + ABIValue, DebugFileMap, DebugInfo, - EventAbi, } from '@aztec/foundation/abi'; export const AZTEC_PRIVATE_ATTRIBUTE = 'aztec(private)'; @@ -68,7 +68,10 @@ export interface NoirCompiledContract { /** The functions of the contract. */ functions: NoirFunctionEntry[]; /** The events of the contract */ - events: EventAbi[]; + outputs: { + structs: Record; + globals: Record; + }; /** The map of file ID to the source code and path of the file. */ file_map: DebugFileMap; }