Skip to content

Commit

Permalink
fixes and consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
Thunkar committed Mar 22, 2024
1 parent cfbd695 commit 8e9e449
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 56 deletions.
6 changes: 3 additions & 3 deletions avm-transpiler/src/transpile_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct TranspiledContract {
pub name: String,
// Functions can be ACIR or AVM
pub functions: Vec<AvmOrAcirContractFunction>,
pub events: serde_json::Value,
pub outputs: serde_json::Value,
pub file_map: serde_json::Value,
//pub warnings: serde_json::Value,
}
Expand All @@ -29,7 +29,7 @@ pub struct CompiledAcirContract {
pub noir_version: String,
pub name: String,
pub functions: Vec<AcirContractFunction>,
pub events: serde_json::Value,
pub outputs: serde_json::Value,
pub file_map: serde_json::Value,
//pub warnings: serde_json::Value,
}
Expand Down Expand Up @@ -113,7 +113,7 @@ impl From<CompiledAcirContract> 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,
}
Expand Down
50 changes: 31 additions & 19 deletions noir/noir-repo/compiler/wasm/src/types/noir_artifact.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
import { Abi, AbiType } from '@noir-lang/types';

/**
* A named type.
* A basic value.
*/
export interface ABIVariable {
export interface BasicValue<T extends string, V> {
/**
* 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;
}

/**
Expand Down Expand Up @@ -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<string, AbiType[]>;
globals: Record<string, ABIValue[]>;
};
/** The map of file ID to the source code and path of the file. */
file_map: DebugFileMap;
}
Expand Down
16 changes: 8 additions & 8 deletions noir/noir-repo/tooling/noirc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,18 @@ pub enum AbiValue {
Field {
value: FieldElement,
},
Array {
values: Vec<AbiValue>,
},
Integer {
value: i128,
},
Boolean {
value: bool,
},
String {
value: String,
},
Array {
value: Vec<AbiValue>,
},
Struct {
#[serde(
serialize_with = "serialization::serialize_struct_field_values",
Expand All @@ -540,9 +543,6 @@ pub enum AbiValue {
Tuple {
fields: Vec<AbiValue>,
},
String {
value: String,
},
}

impl AbiValue {
Expand All @@ -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(
Expand All @@ -576,7 +576,7 @@ impl AbiValue {
)
})
.collect();
Self::Array { values }
Self::Array { value }
}
_ => unreachable!("Repeated arrays cannot be used in the abi"),
},
Expand Down
5 changes: 4 additions & 1 deletion yarn-project/aztec.js/src/contract/contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ describe('Contract Class', () => {
debugSymbols: '',
},
],
events: [],
outputs: {
structs: {},
globals: {},
},
fileMap: {},
};

Expand Down
5 changes: 4 additions & 1 deletion yarn-project/circuit-types/src/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
});

Expand Down
2 changes: 1 addition & 1 deletion yarn-project/circuits.js/src/contract/artifact_hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

Expand Down
5 changes: 4 additions & 1 deletion yarn-project/cli/src/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export const mockContractArtifact: ContractArtifact = {
debugSymbols: '',
},
],
events: [],
outputs: {
structs: {},
globals: {},
},
fileMap: {},
};
50 changes: 31 additions & 19 deletions yarn-project/foundation/src/abi/abi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@ import { inflate } from 'pako';

import { type FunctionSelector } from './function_selector.js';

/**
* A basic value.
*/
export interface BasicValue<T extends string, V> {
/**
* 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.
*/
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -258,7 +267,10 @@ export interface ContractArtifact {
/**
* The events of the contract.
*/
events: EventAbi[];
outputs: {
structs: Record<string, ABIType[]>;
globals: Record<string, ABIValue[]>;
};

/**
* The map of file ID to the source code and path of the file.
Expand Down
2 changes: 1 addition & 1 deletion yarn-project/types/src/abi/contract_artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
7 changes: 5 additions & 2 deletions yarn-project/types/src/noir/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {
ABIParameter,
ABIParameterVisibility,
ABIType,
ABIValue,
DebugFileMap,
DebugInfo,
EventAbi,
} from '@aztec/foundation/abi';

export const AZTEC_PRIVATE_ATTRIBUTE = 'aztec(private)';
Expand Down Expand Up @@ -68,7 +68,10 @@ export interface NoirCompiledContract {
/** The functions of the contract. */
functions: NoirFunctionEntry[];
/** The events of the contract */
events: EventAbi[];
outputs: {
structs: Record<string, ABIType[]>;
globals: Record<string, ABIValue[]>;
};
/** The map of file ID to the source code and path of the file. */
file_map: DebugFileMap;
}
Expand Down

0 comments on commit 8e9e449

Please sign in to comment.