diff --git a/noir/.github/workflows/release.yml b/noir/.github/workflows/release.yml index 7dfc844d18f..71a0ab6d894 100644 --- a/noir/.github/workflows/release.yml +++ b/noir/.github/workflows/release.yml @@ -87,7 +87,7 @@ jobs: - name: Cut a new version working-directory: ./docs - run: yarn docusaurus docs:version ${{ steps.noir-version.outputs.semver }} + run: yarn version ${{ steps.noir-version.outputs.semver }} - name: Configure git run: | diff --git a/noir/.gitrepo b/noir/.gitrepo index 940fb7a0483..aca0a674c07 100644 --- a/noir/.gitrepo +++ b/noir/.gitrepo @@ -6,7 +6,7 @@ [subrepo] remote = https://github.com/noir-lang/noir branch = aztec-packages - commit = ea6aebcc4e190d9dbadaf1dd0f70950651eed615 + commit = 2badd023eab159b7892bd507897bedb360bebebe parent = 3b25737324e45bdfb49233f73065569301282cc0 method = merge cmdver = 0.4.6 diff --git a/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs b/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs index 970eb9390bb..e184401c5d4 100644 --- a/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs +++ b/noir/acvm-repo/acvm/src/compiler/transformers/mod.rs @@ -99,61 +99,8 @@ pub(super) fn transform_internal( } } Opcode::BlackBoxFuncCall(ref func) => { - match func { - acir::circuit::opcodes::BlackBoxFuncCall::AND { output, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::XOR { output, .. } => { - transformer.mark_solvable(*output); - } - acir::circuit::opcodes::BlackBoxFuncCall::RANGE { .. } - | acir::circuit::opcodes::BlackBoxFuncCall::RecursiveAggregation { .. } - | acir::circuit::opcodes::BlackBoxFuncCall::BigIntFromLeBytes { .. } - | acir::circuit::opcodes::BlackBoxFuncCall::BigIntAdd { .. } - | acir::circuit::opcodes::BlackBoxFuncCall::BigIntNeg { .. } - | acir::circuit::opcodes::BlackBoxFuncCall::BigIntMul { .. } - | acir::circuit::opcodes::BlackBoxFuncCall::BigIntDiv { .. } => (), - acir::circuit::opcodes::BlackBoxFuncCall::SHA256 { outputs, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::Keccak256 { outputs, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::Keccak256VariableLength { - outputs, - .. - } - | acir::circuit::opcodes::BlackBoxFuncCall::Keccakf1600 { outputs, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::Blake2s { outputs, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::Blake3 { outputs, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::BigIntToLeBytes { - outputs, .. - } - | acir::circuit::opcodes::BlackBoxFuncCall::Poseidon2Permutation { - outputs, - .. - } - | acir::circuit::opcodes::BlackBoxFuncCall::Sha256Compression { - outputs, .. - } => { - for witness in outputs { - transformer.mark_solvable(*witness); - } - } - acir::circuit::opcodes::BlackBoxFuncCall::FixedBaseScalarMul { - outputs, - .. - } - | acir::circuit::opcodes::BlackBoxFuncCall::EmbeddedCurveAdd { - outputs, .. - } - | acir::circuit::opcodes::BlackBoxFuncCall::PedersenCommitment { - outputs, - .. - } => { - transformer.mark_solvable(outputs.0); - transformer.mark_solvable(outputs.1); - } - acir::circuit::opcodes::BlackBoxFuncCall::EcdsaSecp256k1 { output, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::EcdsaSecp256r1 { output, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::SchnorrVerify { output, .. } - | acir::circuit::opcodes::BlackBoxFuncCall::PedersenHash { output, .. } => { - transformer.mark_solvable(*output); - } + for witness in func.get_outputs_vec() { + transformer.mark_solvable(witness); } new_acir_opcode_positions.push(acir_opcode_positions[index]); diff --git a/noir/acvm-repo/acvm_js/src/logging.rs b/noir/acvm-repo/acvm_js/src/logging.rs index f5d71fae067..483c23ab624 100644 --- a/noir/acvm-repo/acvm_js/src/logging.rs +++ b/noir/acvm-repo/acvm_js/src/logging.rs @@ -1,3 +1,4 @@ +use js_sys::{Error, JsString}; use tracing_subscriber::prelude::*; use tracing_subscriber::EnvFilter; use tracing_web::MakeWebConsoleWriter; @@ -7,12 +8,15 @@ use wasm_bindgen::prelude::*; /// /// @param {LogLevel} level - The maximum level of logging to be emitted. #[wasm_bindgen(js_name = initLogLevel, skip_jsdoc)] -pub fn init_log_level(filter: String) { +pub fn init_log_level(filter: String) -> Result<(), JsLogInitError> { // Set the static variable from Rust use std::sync::Once; - let filter: EnvFilter = - filter.parse().expect("Could not parse log filter while initializing logger"); + let filter: EnvFilter = filter.parse().map_err(|err| { + JsLogInitError::constructor( + format!("Could not parse log filter while initializing logger: {err}").into(), + ) + })?; static SET_HOOK: Once = Once::new(); SET_HOOK.call_once(|| { @@ -23,4 +27,19 @@ pub fn init_log_level(filter: String) { tracing_subscriber::registry().with(fmt_layer.with_filter(filter)).init(); }); + + Ok(()) +} + +/// `LogInitError` is a raw js error. +/// It'd be ideal that `LogInitError` was a subclass of Error, but for that we'd need to use JS snippets or a js module. +/// Currently JS snippets don't work with a nodejs target. And a module would be too much for just a custom error type. +#[wasm_bindgen] +extern "C" { + #[wasm_bindgen(extends = Error, js_name = "LogInitError", typescript_type = "LogInitError")] + #[derive(Clone, Debug, PartialEq, Eq)] + pub type JsLogInitError; + + #[wasm_bindgen(constructor, js_class = "Error")] + fn constructor(message: JsString) -> JsLogInitError; } diff --git a/noir/aztec_macros/src/lib.rs b/noir/aztec_macros/src/lib.rs index e2c232e3233..b1d401b4e53 100644 --- a/noir/aztec_macros/src/lib.rs +++ b/noir/aztec_macros/src/lib.rs @@ -846,11 +846,11 @@ fn make_return_push(push_value: Expression) -> Statement { /// Make Return push array /// /// Translates to: -/// `context.return_values.push_array({push_value})` -fn make_return_push_array(push_value: Expression) -> Statement { +/// `context.return_values.extend_from_array({push_value})` +fn make_return_extend_from_array(push_value: Expression) -> Statement { make_statement(StatementKind::Semi(method_call( context_return_values(), - "push_array", + "extend_from_array", vec![push_value], ))) } @@ -859,14 +859,14 @@ fn make_return_push_array(push_value: Expression) -> Statement { /// /// Translates to: /// ```noir -/// `context.return_values.push_array({push_value}.serialize())` +/// `context.return_values.extend_from_array({push_value}.serialize())` fn make_struct_return_type(expression: Expression) -> Statement { let serialized_call = method_call( expression, // variable "serialize", // method name vec![], // args ); - make_return_push_array(serialized_call) + make_return_extend_from_array(serialized_call) } /// Make array return type diff --git a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 217ea3f7584..d56d0ade3c4 100644 --- a/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/noir/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -400,8 +400,8 @@ impl AcirContext { // Operands are booleans. // // a ^ b == a + b - 2*a*b - let sum = self.add_var(lhs, rhs)?; let prod = self.mul_var(lhs, rhs)?; + let sum = self.add_var(lhs, rhs)?; self.add_mul_var(sum, -FieldElement::from(2_i128), prod) } else { let inputs = vec![AcirValue::Var(lhs, typ.clone()), AcirValue::Var(rhs, typ)]; @@ -461,8 +461,8 @@ impl AcirContext { if bit_size == 1 { // Operands are booleans // a + b - ab - let sum = self.add_var(lhs, rhs)?; let mul = self.mul_var(lhs, rhs)?; + let sum = self.add_var(lhs, rhs)?; self.sub_var(sum, mul) } else { // Implement OR in terms of AND diff --git a/noir/docs/docs/noir/concepts/data_types/fields.md b/noir/docs/docs/noir/concepts/data_types/fields.md index a1c67945d66..7870c98c858 100644 --- a/noir/docs/docs/noir/concepts/data_types/fields.md +++ b/noir/docs/docs/noir/concepts/data_types/fields.md @@ -157,6 +157,23 @@ fn main() { } ``` +### assert_max_bit_size + +Adds a constraint to specify that the field can be represented with `bit_size` number of bits + +```rust +fn assert_max_bit_size(self, bit_size: u32) +``` + +example: + +```rust +fn main() { + let field = 2 + field.assert_max_bit_size(32); +} +``` + ### sgn0 Parity of (prime) Field element, i.e. sgn0(x mod p) = 0 if x ∈ \{0, ..., p-1\} is even, otherwise sgn0(x mod p) = 1. diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/.nojekyll b/noir/docs/docs/reference/NoirJS/backend_barretenberg/.nojekyll deleted file mode 100644 index e2ac6616add..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/.nojekyll +++ /dev/null @@ -1 +0,0 @@ -TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend.md b/noir/docs/docs/reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend.md deleted file mode 100644 index af4a7558cdf..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend.md +++ /dev/null @@ -1,202 +0,0 @@ -# BarretenbergBackend - -## Implements - -- [`Backend`](../interfaces/Backend.md) - -## Constructors - -### new BarretenbergBackend(acirCircuit, options) - -```ts -new BarretenbergBackend(acirCircuit, options): BarretenbergBackend -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `acirCircuit` | [`CompiledCircuit`](../type-aliases/CompiledCircuit.md) | -| `options` | [`BackendOptions`](../type-aliases/BackendOptions.md) | - -#### Returns - -[`BarretenbergBackend`](BarretenbergBackend.md) - -## Methods - -### destroy() - -```ts -destroy(): Promise -``` - -#### Returns - -`Promise`\<`void`\> - -#### Implementation of - -[`Backend`](../interfaces/Backend.md).[`destroy`](../interfaces/Backend.md#destroy) - -#### Description - -Destroys the backend - -*** - -### generateFinalProof() - -```ts -generateFinalProof(decompressedWitness): Promise -``` - -Generate a final proof. This is the proof for the circuit which will verify -intermediate proofs and or can be seen as the proof created for regular circuits. - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `decompressedWitness` | `Uint8Array` | - -#### Returns - -`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> - -#### Implementation of - -[`Backend`](../interfaces/Backend.md).[`generateFinalProof`](../interfaces/Backend.md#generatefinalproof) - -*** - -### generateIntermediateProof() - -```ts -generateIntermediateProof(witness): Promise -``` - -Generates an intermediate proof. This is the proof that can be verified -in another circuit. - -This is sometimes referred to as a recursive proof. -We avoid this terminology as the only property of this proof -that matters is the fact that it is easy to verify in another circuit. -We _could_ choose to verify this proof outside of a circuit just as easily. - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `witness` | `Uint8Array` | - -#### Returns - -`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> - -#### Implementation of - -[`Backend`](../interfaces/Backend.md).[`generateIntermediateProof`](../interfaces/Backend.md#generateintermediateproof) - -#### Example - -```typescript -const intermediateProof = await backend.generateIntermediateProof(witness); -``` - -*** - -### generateIntermediateProofArtifacts() - -```ts -generateIntermediateProofArtifacts(proofData, numOfPublicInputs): Promise -``` - -Generates artifacts that will be passed to a circuit that will verify this proof. - -Instead of passing the proof and verification key as a byte array, we pass them -as fields which makes it cheaper to verify in a circuit. - -The proof that is passed here will have been created using the `generateIntermediateProof` -method. - -The number of public inputs denotes how many public inputs are in the inner proof. - -#### Parameters - -| Parameter | Type | Default value | -| :------ | :------ | :------ | -| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | `undefined` | -| `numOfPublicInputs` | `number` | `0` | - -#### Returns - -`Promise`\<`object`\> - -#### Implementation of - -[`Backend`](../interfaces/Backend.md).[`generateIntermediateProofArtifacts`](../interfaces/Backend.md#generateintermediateproofartifacts) - -#### Example - -```typescript -const artifacts = await backend.generateIntermediateProofArtifacts(proof, numOfPublicInputs); -``` - -*** - -### verifyFinalProof() - -```ts -verifyFinalProof(proofData): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | - -#### Returns - -`Promise`\<`boolean`\> - -#### Implementation of - -[`Backend`](../interfaces/Backend.md).[`verifyFinalProof`](../interfaces/Backend.md#verifyfinalproof) - -#### Description - -Verifies a final proof - -*** - -### verifyIntermediateProof() - -```ts -verifyIntermediateProof(proofData): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | - -#### Returns - -`Promise`\<`boolean`\> - -#### Implementation of - -[`Backend`](../interfaces/Backend.md).[`verifyIntermediateProof`](../interfaces/Backend.md#verifyintermediateproof) - -#### Example - -```typescript -const isValidIntermediate = await backend.verifyIntermediateProof(proof); -``` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/index.md b/noir/docs/docs/reference/NoirJS/backend_barretenberg/index.md deleted file mode 100644 index e32501acb71..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/index.md +++ /dev/null @@ -1,46 +0,0 @@ -# backend_barretenberg - -## Exports - -### Classes - -| Class | Description | -| :------ | :------ | -| [BarretenbergBackend](classes/BarretenbergBackend.md) | - | - -### Interfaces - -| Interface | Description | -| :------ | :------ | -| [Backend](interfaces/Backend.md) | - | - -### Type Aliases - -| Type alias | Description | -| :------ | :------ | -| [BackendOptions](type-aliases/BackendOptions.md) | - | -| [CompiledCircuit](type-aliases/CompiledCircuit.md) | - | -| [ProofData](type-aliases/ProofData.md) | - | - -## Functions - -### publicInputsToWitnessMap() - -```ts -publicInputsToWitnessMap(publicInputs, abi): WitnessMap -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `publicInputs` | `string`[] | -| `abi` | `Abi` | - -#### Returns - -`WitnessMap` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/interfaces/Backend.md b/noir/docs/docs/reference/NoirJS/backend_barretenberg/interfaces/Backend.md deleted file mode 100644 index 3eb9645c8d2..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/interfaces/Backend.md +++ /dev/null @@ -1,132 +0,0 @@ -# Backend - -## Methods - -### destroy() - -```ts -destroy(): Promise -``` - -#### Returns - -`Promise`\<`void`\> - -#### Description - -Destroys the backend - -*** - -### generateFinalProof() - -```ts -generateFinalProof(decompressedWitness): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `decompressedWitness` | `Uint8Array` | - -#### Returns - -`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> - -#### Description - -Generates a final proof (not meant to be verified in another circuit) - -*** - -### generateIntermediateProof() - -```ts -generateIntermediateProof(decompressedWitness): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `decompressedWitness` | `Uint8Array` | - -#### Returns - -`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> - -#### Description - -Generates an intermediate proof (meant to be verified in another circuit) - -*** - -### generateIntermediateProofArtifacts() - -```ts -generateIntermediateProofArtifacts(proofData, numOfPublicInputs): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | -| `numOfPublicInputs` | `number` | - -#### Returns - -`Promise`\<`object`\> - -#### Description - -Retrieves the artifacts from a proof in the Field format - -*** - -### verifyFinalProof() - -```ts -verifyFinalProof(proofData): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | - -#### Returns - -`Promise`\<`boolean`\> - -#### Description - -Verifies a final proof - -*** - -### verifyIntermediateProof() - -```ts -verifyIntermediateProof(proofData): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | - -#### Returns - -`Promise`\<`boolean`\> - -#### Description - -Verifies an intermediate proof - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions.md b/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions.md deleted file mode 100644 index 266ade75d17..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions.md +++ /dev/null @@ -1,19 +0,0 @@ -# BackendOptions - -```ts -type BackendOptions: object; -``` - -## Description - -An options object, currently only used to specify the number of threads to use. - -## Type declaration - -| Member | Type | Description | -| :------ | :------ | :------ | -| `threads` | `number` | **Description**

Number of threads | - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit.md b/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit.md deleted file mode 100644 index 34e0dd04205..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit.md +++ /dev/null @@ -1,20 +0,0 @@ -# CompiledCircuit - -```ts -type CompiledCircuit: object; -``` - -## Description - -The representation of a compiled circuit - -## Type declaration - -| Member | Type | Description | -| :------ | :------ | :------ | -| `abi` | `Abi` | **Description**

ABI representation of the circuit | -| `bytecode` | `string` | **Description**

The bytecode of the circuit | - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/ProofData.md b/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/ProofData.md deleted file mode 100644 index 05cebbc4e94..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/type-aliases/ProofData.md +++ /dev/null @@ -1,20 +0,0 @@ -# ProofData - -```ts -type ProofData: object; -``` - -## Description - -The representation of a proof - -## Type declaration - -| Member | Type | Description | -| :------ | :------ | :------ | -| `proof` | `Uint8Array` | **Description**

An byte array representing the proof | -| `publicInputs` | `string`[] | **Description**

Public inputs of a proof | - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/backend_barretenberg/typedoc-sidebar.cjs b/noir/docs/docs/reference/NoirJS/backend_barretenberg/typedoc-sidebar.cjs deleted file mode 100644 index 2aaa55bccf6..00000000000 --- a/noir/docs/docs/reference/NoirJS/backend_barretenberg/typedoc-sidebar.cjs +++ /dev/null @@ -1,4 +0,0 @@ -// @ts-check -/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ -const typedocSidebar = { items: [{"type":"category","label":"Classes","items":[{"type":"doc","id":"reference/NoirJS/backend_barretenberg/classes/BarretenbergBackend","label":"BarretenbergBackend"}]},{"type":"category","label":"Interfaces","items":[{"type":"doc","id":"reference/NoirJS/backend_barretenberg/interfaces/Backend","label":"Backend"}]},{"type":"category","label":"Type Aliases","items":[{"type":"doc","id":"reference/NoirJS/backend_barretenberg/type-aliases/BackendOptions","label":"BackendOptions"},{"type":"doc","id":"reference/NoirJS/backend_barretenberg/type-aliases/CompiledCircuit","label":"CompiledCircuit"},{"type":"doc","id":"reference/NoirJS/backend_barretenberg/type-aliases/ProofData","label":"ProofData"}]}]}; -module.exports = typedocSidebar.items; \ No newline at end of file diff --git a/noir/docs/docs/reference/NoirJS/noir_js/.nojekyll b/noir/docs/docs/reference/NoirJS/noir_js/.nojekyll deleted file mode 100644 index e2ac6616add..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/.nojekyll +++ /dev/null @@ -1 +0,0 @@ -TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false. \ No newline at end of file diff --git a/noir/docs/docs/reference/NoirJS/noir_js/classes/Noir.md b/noir/docs/docs/reference/NoirJS/noir_js/classes/Noir.md deleted file mode 100644 index 34e20d99684..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/classes/Noir.md +++ /dev/null @@ -1,132 +0,0 @@ -# Noir - -## Constructors - -### new Noir(circuit, backend) - -```ts -new Noir(circuit, backend?): Noir -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `circuit` | [`CompiledCircuit`](../type-aliases/CompiledCircuit.md) | -| `backend`? | `Backend` | - -#### Returns - -[`Noir`](Noir.md) - -## Methods - -### destroy() - -```ts -destroy(): Promise -``` - -#### Returns - -`Promise`\<`void`\> - -#### Description - -Destroys the underlying backend instance. - -#### Example - -```typescript -await noir.destroy(); -``` - -*** - -### execute() - -```ts -execute(inputs, foreignCallHandler?): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `inputs` | [`InputMap`](../type-aliases/InputMap.md) | -| `foreignCallHandler`? | [`ForeignCallHandler`](../type-aliases/ForeignCallHandler.md) | - -#### Returns - -`Promise`\<`object`\> - -#### Description - -Allows to execute a circuit to get its witness and return value. - -#### Example - -```typescript -async execute(inputs) -``` - -*** - -### generateFinalProof() - -```ts -generateFinalProof(inputs, foreignCallHandler?): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `inputs` | [`InputMap`](../type-aliases/InputMap.md) | -| `foreignCallHandler`? | [`ForeignCallHandler`](../type-aliases/ForeignCallHandler.md) | - -#### Returns - -`Promise`\<[`ProofData`](../type-aliases/ProofData.md)\> - -#### Description - -Generates a witness and a proof given an object as input. - -#### Example - -```typescript -async generateFinalProof(input) -``` - -*** - -### verifyFinalProof() - -```ts -verifyFinalProof(proofData): Promise -``` - -#### Parameters - -| Parameter | Type | -| :------ | :------ | -| `proofData` | [`ProofData`](../type-aliases/ProofData.md) | - -#### Returns - -`Promise`\<`boolean`\> - -#### Description - -Instantiates the verification key and verifies a proof. - -#### Example - -```typescript -async verifyFinalProof(proof) -``` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/functions/and.md b/noir/docs/docs/reference/NoirJS/noir_js/functions/and.md deleted file mode 100644 index c783283e396..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/functions/and.md +++ /dev/null @@ -1,22 +0,0 @@ -# and() - -```ts -and(lhs, rhs): string -``` - -Performs a bitwise AND operation between `lhs` and `rhs` - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `lhs` | `string` | | -| `rhs` | `string` | | - -## Returns - -`string` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/functions/blake2s256.md b/noir/docs/docs/reference/NoirJS/noir_js/functions/blake2s256.md deleted file mode 100644 index 7882d0da8d5..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/functions/blake2s256.md +++ /dev/null @@ -1,21 +0,0 @@ -# blake2s256() - -```ts -blake2s256(inputs): Uint8Array -``` - -Calculates the Blake2s256 hash of the input bytes - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `inputs` | `Uint8Array` | | - -## Returns - -`Uint8Array` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify.md b/noir/docs/docs/reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify.md deleted file mode 100644 index 5e3cd53e9d3..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify.md +++ /dev/null @@ -1,28 +0,0 @@ -# ecdsa\_secp256k1\_verify() - -```ts -ecdsa_secp256k1_verify( - hashed_msg, - public_key_x_bytes, - public_key_y_bytes, - signature): boolean -``` - -Verifies a ECDSA signature over the secp256k1 curve. - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `hashed_msg` | `Uint8Array` | | -| `public_key_x_bytes` | `Uint8Array` | | -| `public_key_y_bytes` | `Uint8Array` | | -| `signature` | `Uint8Array` | | - -## Returns - -`boolean` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify.md b/noir/docs/docs/reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify.md deleted file mode 100644 index 0b20ff68957..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify.md +++ /dev/null @@ -1,28 +0,0 @@ -# ecdsa\_secp256r1\_verify() - -```ts -ecdsa_secp256r1_verify( - hashed_msg, - public_key_x_bytes, - public_key_y_bytes, - signature): boolean -``` - -Verifies a ECDSA signature over the secp256r1 curve. - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `hashed_msg` | `Uint8Array` | | -| `public_key_x_bytes` | `Uint8Array` | | -| `public_key_y_bytes` | `Uint8Array` | | -| `signature` | `Uint8Array` | | - -## Returns - -`boolean` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/functions/keccak256.md b/noir/docs/docs/reference/NoirJS/noir_js/functions/keccak256.md deleted file mode 100644 index d10f155ce86..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/functions/keccak256.md +++ /dev/null @@ -1,21 +0,0 @@ -# keccak256() - -```ts -keccak256(inputs): Uint8Array -``` - -Calculates the Keccak256 hash of the input bytes - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `inputs` | `Uint8Array` | | - -## Returns - -`Uint8Array` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/functions/sha256.md b/noir/docs/docs/reference/NoirJS/noir_js/functions/sha256.md deleted file mode 100644 index 6ba4ecac022..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/functions/sha256.md +++ /dev/null @@ -1,21 +0,0 @@ -# sha256() - -```ts -sha256(inputs): Uint8Array -``` - -Calculates the SHA256 hash of the input bytes - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `inputs` | `Uint8Array` | | - -## Returns - -`Uint8Array` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/functions/xor.md b/noir/docs/docs/reference/NoirJS/noir_js/functions/xor.md deleted file mode 100644 index 8d762b895d3..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/functions/xor.md +++ /dev/null @@ -1,22 +0,0 @@ -# xor() - -```ts -xor(lhs, rhs): string -``` - -Performs a bitwise XOR operation between `lhs` and `rhs` - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `lhs` | `string` | | -| `rhs` | `string` | | - -## Returns - -`string` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/index.md b/noir/docs/docs/reference/NoirJS/noir_js/index.md deleted file mode 100644 index d600e21b299..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/index.md +++ /dev/null @@ -1,37 +0,0 @@ -# noir_js - -## Exports - -### Classes - -| Class | Description | -| :------ | :------ | -| [Noir](classes/Noir.md) | - | - -### Type Aliases - -| Type alias | Description | -| :------ | :------ | -| [CompiledCircuit](type-aliases/CompiledCircuit.md) | - | -| [ForeignCallHandler](type-aliases/ForeignCallHandler.md) | A callback which performs an foreign call and returns the response. | -| [ForeignCallInput](type-aliases/ForeignCallInput.md) | - | -| [ForeignCallOutput](type-aliases/ForeignCallOutput.md) | - | -| [InputMap](type-aliases/InputMap.md) | - | -| [ProofData](type-aliases/ProofData.md) | - | -| [WitnessMap](type-aliases/WitnessMap.md) | - | - -### Functions - -| Function | Description | -| :------ | :------ | -| [and](functions/and.md) | Performs a bitwise AND operation between `lhs` and `rhs` | -| [blake2s256](functions/blake2s256.md) | Calculates the Blake2s256 hash of the input bytes | -| [ecdsa\_secp256k1\_verify](functions/ecdsa_secp256k1_verify.md) | Verifies a ECDSA signature over the secp256k1 curve. | -| [ecdsa\_secp256r1\_verify](functions/ecdsa_secp256r1_verify.md) | Verifies a ECDSA signature over the secp256r1 curve. | -| [keccak256](functions/keccak256.md) | Calculates the Keccak256 hash of the input bytes | -| [sha256](functions/sha256.md) | Calculates the SHA256 hash of the input bytes | -| [xor](functions/xor.md) | Performs a bitwise XOR operation between `lhs` and `rhs` | - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/CompiledCircuit.md b/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/CompiledCircuit.md deleted file mode 100644 index 34e0dd04205..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/CompiledCircuit.md +++ /dev/null @@ -1,20 +0,0 @@ -# CompiledCircuit - -```ts -type CompiledCircuit: object; -``` - -## Description - -The representation of a compiled circuit - -## Type declaration - -| Member | Type | Description | -| :------ | :------ | :------ | -| `abi` | `Abi` | **Description**

ABI representation of the circuit | -| `bytecode` | `string` | **Description**

The bytecode of the circuit | - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md b/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md deleted file mode 100644 index 812b8b16481..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallHandler.md +++ /dev/null @@ -1,24 +0,0 @@ -# ForeignCallHandler - -```ts -type ForeignCallHandler: (name, inputs) => Promise; -``` - -A callback which performs an foreign call and returns the response. - -## Parameters - -| Parameter | Type | Description | -| :------ | :------ | :------ | -| `name` | `string` | The identifier for the type of foreign call being performed. | -| `inputs` | [`ForeignCallInput`](ForeignCallInput.md)[] | An array of hex encoded inputs to the foreign call. | - -## Returns - -`Promise`\<[`ForeignCallOutput`](ForeignCallOutput.md)[]\> - -outputs - An array of hex encoded outputs containing the results of the foreign call. - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallInput.md b/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallInput.md deleted file mode 100644 index dd95809186a..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallInput.md +++ /dev/null @@ -1,9 +0,0 @@ -# ForeignCallInput - -```ts -type ForeignCallInput: string[]; -``` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md b/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md deleted file mode 100644 index b71fb78a946..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ForeignCallOutput.md +++ /dev/null @@ -1,9 +0,0 @@ -# ForeignCallOutput - -```ts -type ForeignCallOutput: string | string[]; -``` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/InputMap.md b/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/InputMap.md deleted file mode 100644 index c714e999d93..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/InputMap.md +++ /dev/null @@ -1,13 +0,0 @@ -# InputMap - -```ts -type InputMap: object; -``` - -## Index signature - - \[`key`: `string`\]: `InputValue` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ProofData.md b/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ProofData.md deleted file mode 100644 index 05cebbc4e94..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/ProofData.md +++ /dev/null @@ -1,20 +0,0 @@ -# ProofData - -```ts -type ProofData: object; -``` - -## Description - -The representation of a proof - -## Type declaration - -| Member | Type | Description | -| :------ | :------ | :------ | -| `proof` | `Uint8Array` | **Description**

An byte array representing the proof | -| `publicInputs` | `string`[] | **Description**

Public inputs of a proof | - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/WitnessMap.md b/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/WitnessMap.md deleted file mode 100644 index 258c46f9d0c..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/type-aliases/WitnessMap.md +++ /dev/null @@ -1,9 +0,0 @@ -# WitnessMap - -```ts -type WitnessMap: Map; -``` - -*** - -Generated using [typedoc-plugin-markdown](https://www.npmjs.com/package/typedoc-plugin-markdown) and [TypeDoc](https://typedoc.org/) diff --git a/noir/docs/docs/reference/NoirJS/noir_js/typedoc-sidebar.cjs b/noir/docs/docs/reference/NoirJS/noir_js/typedoc-sidebar.cjs deleted file mode 100644 index fe2629ddc9f..00000000000 --- a/noir/docs/docs/reference/NoirJS/noir_js/typedoc-sidebar.cjs +++ /dev/null @@ -1,4 +0,0 @@ -// @ts-check -/** @type {import('@docusaurus/plugin-content-docs').SidebarsConfig} */ -const typedocSidebar = { items: [{"type":"category","label":"Classes","items":[{"type":"doc","id":"reference/NoirJS/noir_js/classes/Noir","label":"Noir"}]},{"type":"category","label":"Type Aliases","items":[{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/CompiledCircuit","label":"CompiledCircuit"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ForeignCallHandler","label":"ForeignCallHandler"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ForeignCallInput","label":"ForeignCallInput"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ForeignCallOutput","label":"ForeignCallOutput"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/InputMap","label":"InputMap"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/ProofData","label":"ProofData"},{"type":"doc","id":"reference/NoirJS/noir_js/type-aliases/WitnessMap","label":"WitnessMap"}]},{"type":"category","label":"Functions","items":[{"type":"doc","id":"reference/NoirJS/noir_js/functions/and","label":"and"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/blake2s256","label":"blake2s256"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/ecdsa_secp256k1_verify","label":"ecdsa_secp256k1_verify"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/ecdsa_secp256r1_verify","label":"ecdsa_secp256r1_verify"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/keccak256","label":"keccak256"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/sha256","label":"sha256"},{"type":"doc","id":"reference/NoirJS/noir_js/functions/xor","label":"xor"}]}]}; -module.exports = typedocSidebar.items; \ No newline at end of file diff --git a/noir/docs/docusaurus.config.ts b/noir/docs/docusaurus.config.ts index 4e0d053f61e..d1d344ba635 100644 --- a/noir/docs/docusaurus.config.ts +++ b/noir/docs/docusaurus.config.ts @@ -155,7 +155,7 @@ export default { entryPoints: ['../tooling/noir_js/src/index.ts'], tsconfig: '../tooling/noir_js/tsconfig.json', entryPointStrategy: 'resolve', - out: 'docs/reference/NoirJS/noir_js', + out: 'processed-docs/reference/NoirJS/noir_js', plugin: ['typedoc-plugin-markdown'], name: 'noir_js', disableSources: true, @@ -186,7 +186,7 @@ export default { entryPoints: ['../tooling/noir_js_backend_barretenberg/src/index.ts'], tsconfig: '../tooling/noir_js_backend_barretenberg/tsconfig.json', entryPointStrategy: 'resolve', - out: 'docs/reference/NoirJS/backend_barretenberg', + out: 'processed-docs/reference/NoirJS/backend_barretenberg', plugin: ['typedoc-plugin-markdown'], name: 'backend_barretenberg', disableSources: true, diff --git a/noir/docs/package.json b/noir/docs/package.json index 6c706e4f514..71b624ff565 100644 --- a/noir/docs/package.json +++ b/noir/docs/package.json @@ -7,7 +7,8 @@ "start": "yarn preprocess && docusaurus start", "build": "yarn preprocess && yarn version::stables && docusaurus build", "version::stables": "ts-node ./scripts/setStable.ts", - "serve": "serve build" + "serve": "serve build", + "version": "yarn preprocess && docusaurus docs:version" }, "dependencies": { "@docusaurus/core": "^3.0.1", diff --git a/noir/noir_stdlib/src/bigint.nr b/noir/noir_stdlib/src/bigint.nr index f3ecfba8343..14790f69241 100644 --- a/noir/noir_stdlib/src/bigint.nr +++ b/noir/noir_stdlib/src/bigint.nr @@ -1,4 +1,3 @@ - use crate::ops::{Add, Sub, Mul, Div, Rem,}; struct BigInt { @@ -8,21 +7,21 @@ struct BigInt { impl BigInt { #[builtin(bigint_add)] - pub fn bigint_add(self, other: BigInt) -> BigInt { + pub fn bigint_add(_self: Self, _other: BigInt) -> BigInt { } #[builtin(bigint_neg)] - pub fn bigint_neg(self, other: BigInt) -> BigInt { + pub fn bigint_neg(_self: Self, _other: BigInt) -> BigInt { } #[builtin(bigint_mul)] - pub fn bigint_mul(self, other: BigInt) -> BigInt { + pub fn bigint_mul(_self: Self, _other: BigInt) -> BigInt { } #[builtin(bigint_div)] - pub fn bigint_div(self, other: BigInt) -> BigInt { + pub fn bigint_div(_self: Self, _other: BigInt) -> BigInt { } #[builtin(bigint_from_le_bytes)] - pub fn from_le_bytes(bytes: [u8], modulus: [u8]) -> BigInt {} + pub fn from_le_bytes(_bytes: [u8], _modulus: [u8]) -> BigInt {} #[builtin(bigint_to_le_bytes)] - pub fn to_le_bytes(self) -> [u8] {} + pub fn to_le_bytes(_self: Self) -> [u8] {} } impl Add for BigInt { diff --git a/noir/noir_stdlib/src/collections.nr b/noir/noir_stdlib/src/collections.nr index e06c662e658..177ca96816f 100644 --- a/noir/noir_stdlib/src/collections.nr +++ b/noir/noir_stdlib/src/collections.nr @@ -1 +1,2 @@ mod vec; +mod bounded_vec; diff --git a/noir/noir_stdlib/src/collections/bounded_vec.nr b/noir/noir_stdlib/src/collections/bounded_vec.nr new file mode 100644 index 00000000000..332fefa63f9 --- /dev/null +++ b/noir/noir_stdlib/src/collections/bounded_vec.nr @@ -0,0 +1,88 @@ +struct BoundedVec { + storage: [T; MaxLen], + // TODO: change this to return a u64 as Noir now + // uses u64 for indexing + len: Field, + empty_value: T, +} + +impl BoundedVec { + pub fn new(initial_value: T) -> Self { + BoundedVec { storage: [initial_value; MaxLen], len: 0, empty_value: initial_value } + } + + pub fn get(mut self: Self, index: Field) -> T { + assert(index as u64 < self.len as u64); + self.storage[index] + } + + pub fn get_unchecked(mut self: Self, index: Field) -> T { + self.storage[index] + } + + pub fn push(&mut self, elem: T) { + assert(self.len as u64 < MaxLen as u64, "push out of bounds"); + + self.storage[self.len] = elem; + self.len += 1; + } + + pub fn len(self) -> Field { + self.len + } + + pub fn max_len(_self: BoundedVec) -> Field { + MaxLen + } + + // This is a intermediate method, while we don't have an + // .extend method + pub fn storage(self) -> [T; MaxLen] { + self.storage + } + + pub fn extend_from_array(&mut self, array: [T; Len]) { + let new_len = self.len + array.len(); + assert(new_len as u64 <= MaxLen as u64, "extend_from_array out of bounds"); + for i in 0..array.len() { + self.storage[self.len + i] = array[i]; + } + self.len = new_len; + } + + pub fn extend_from_bounded_vec(&mut self, vec: BoundedVec) { + let append_len = vec.len(); + let new_len = self.len + append_len; + assert(new_len as u64 <= MaxLen as u64, "extend_from_bounded_vec out of bounds"); + + let mut exceeded_len = false; + for i in 0..Len { + exceeded_len |= i == append_len; + if !exceeded_len { + self.storage[self.len + (i as Field)] = vec.get_unchecked(i as Field); + } + } + self.len = new_len; + } + + pub fn pop(&mut self) -> T { + assert(self.len as u64 > 0); + self.len -= 1; + + let elem = self.storage[self.len]; + self.storage[self.len] = self.empty_value; + elem + } + + pub fn any(self, predicate: fn[Env](T) -> bool) -> bool { + let mut ret = false; + let mut exceeded_len = false; + for i in 0..MaxLen { + exceeded_len |= i == self.len; + if (!exceeded_len) { + ret |= predicate(self.storage[i]); + } + } + ret + } +} \ No newline at end of file diff --git a/noir/noir_stdlib/src/lib.nr b/noir/noir_stdlib/src/lib.nr index b7c7833277a..90aff3c312b 100644 --- a/noir/noir_stdlib/src/lib.nr +++ b/noir/noir_stdlib/src/lib.nr @@ -25,7 +25,7 @@ mod ops; mod default; mod prelude; mod uint128; -mod bigint; +// mod bigint; // Oracle calls are required to be wrapped in an unconstrained function // Thus, the only argument to the `println` oracle is expected to always be an ident diff --git a/noir/noir_stdlib/src/prelude.nr b/noir/noir_stdlib/src/prelude.nr index 26c6a805d54..3244329aa4b 100644 --- a/noir/noir_stdlib/src/prelude.nr +++ b/noir/noir_stdlib/src/prelude.nr @@ -1,4 +1,5 @@ use crate::collections::vec::Vec; +use crate::collections::bounded_vec::BoundedVec; use crate::option::Option; use crate::{print, println, assert_constant}; use crate::uint128::U128; diff --git a/noir/noir_stdlib/src/scalar_mul.nr b/noir/noir_stdlib/src/scalar_mul.nr index fef2398222f..0e84b4f66fc 100644 --- a/noir/noir_stdlib/src/scalar_mul.nr +++ b/noir/noir_stdlib/src/scalar_mul.nr @@ -1,8 +1,22 @@ +use crate::ops::Add; + struct EmbeddedCurvePoint { x: Field, y: Field, } +impl EmbeddedCurvePoint { + fn double(self) -> EmbeddedCurvePoint { + embedded_curve_add(self, self) + } +} + +impl Add for EmbeddedCurvePoint { + fn add(self, other: EmbeddedCurvePoint) -> EmbeddedCurvePoint { + embedded_curve_add(self, other) + } +} + // Computes a fixed base scalar multiplication over the embedded curve. // For bn254, We have Grumpkin and Baby JubJub. // For bls12-381, we have JubJub and Bandersnatch. @@ -11,12 +25,12 @@ struct EmbeddedCurvePoint { // underlying proof system. #[foreign(fixed_base_scalar_mul)] // docs:start:fixed_base_embedded_curve -pub fn fixed_base_embedded_curve(_low: Field, _high: Field) -> [Field; 2] {} +pub fn fixed_base_embedded_curve( + _low: Field, + _high: Field +) -> [Field; 2] // docs:end:fixed_base_embedded_curve +{} #[foreign(embedded_curve_add)] -pub fn embedded_curve_add(_point1: EmbeddedCurvePoint, _point2: EmbeddedCurvePoint) -> EmbeddedCurvePoint {} - -pub fn embedded_curve_double(point: EmbeddedCurvePoint) -> EmbeddedCurvePoint { - embedded_curve_add(point, point) -} +fn embedded_curve_add(_point1: EmbeddedCurvePoint, _point2: EmbeddedCurvePoint) -> EmbeddedCurvePoint {} diff --git a/noir/test_programs/execution_success/scalar_mul/src/main.nr b/noir/test_programs/execution_success/scalar_mul/src/main.nr index a88754da5d3..e20f47907db 100644 --- a/noir/test_programs/execution_success/scalar_mul/src/main.nr +++ b/noir/test_programs/execution_success/scalar_mul/src/main.nr @@ -20,18 +20,12 @@ fn main( let res = std::scalar_mul::fixed_base_embedded_curve(priv_key, 0); assert(res[0] == pub_x); assert(res[1] == pub_y); - let pub_point= std::scalar_mul::EmbeddedCurvePoint { - x: pub_x, - y: pub_y - }; + let pub_point= std::scalar_mul::EmbeddedCurvePoint { x: pub_x, y: pub_y }; let g1_y = 17631683881184975370165255887551781615748388533673675138860; - let g1= std::scalar_mul::EmbeddedCurvePoint { - x: 1, - y: g1_y - }; + let g1= std::scalar_mul::EmbeddedCurvePoint { x: 1, y: g1_y }; - let res = std::scalar_mul::embedded_curve_double(pub_point); - let double = std::scalar_mul::embedded_curve_add(g1,g1 ); + let res = pub_point.double(); + let double = g1.add(g1); assert(double.x == res.x); } diff --git a/noir/test_programs/noir_test_success/bounded_vec/Nargo.toml b/noir/test_programs/noir_test_success/bounded_vec/Nargo.toml new file mode 100644 index 00000000000..0d58f5872ef --- /dev/null +++ b/noir/test_programs/noir_test_success/bounded_vec/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bounded_vec" +type = "bin" +authors = [""] +compiler_version = ">=0.23.0" + +[dependencies] \ No newline at end of file diff --git a/noir/test_programs/noir_test_success/bounded_vec/Prover.toml b/noir/test_programs/noir_test_success/bounded_vec/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/noir/test_programs/noir_test_success/bounded_vec/src/main.nr b/noir/test_programs/noir_test_success/bounded_vec/src/main.nr new file mode 100644 index 00000000000..d51d2cc3685 --- /dev/null +++ b/noir/test_programs/noir_test_success/bounded_vec/src/main.nr @@ -0,0 +1,105 @@ +#[test] +fn test_vec_push_pop() { + let mut vec: BoundedVec = BoundedVec::new(0); + assert(vec.len == 0); + vec.push(2); + assert(vec.len == 1); + vec.push(4); + assert(vec.len == 2); + vec.push(6); + assert(vec.len == 3); + let x = vec.pop(); + assert(x == 6); + assert(vec.len == 2); + assert(vec.get(0) == 2); + assert(vec.get(1) == 4); +} + +#[test] +fn test_vec_extend_from_array() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.extend_from_array([2, 4]); + assert(vec.len == 2); + assert(vec.get(0) == 2); + assert(vec.get(1) == 4); +} + +#[test(should_fail_with="extend_from_array out of bounds")] +fn test_vec_extend_from_array_out_of_bound() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.extend_from_array([2, 4, 6]); +} + +#[test(should_fail_with="extend_from_array out of bounds")] +fn test_vec_extend_from_array_twice_out_of_bound() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.extend_from_array([2]); + assert(vec.len == 1); + vec.extend_from_array([4, 6]); +} + +#[test(should_fail)] +fn test_vec_get_out_of_bound() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.extend_from_array([2, 4]); + let _x = vec.get(2); +} + +#[test(should_fail)] +fn test_vec_get_not_declared() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.extend_from_array([2]); + let _x = vec.get(1); +} + +#[test(should_fail)] +fn test_vec_get_uninitialized() { + let mut vec: BoundedVec = BoundedVec::new(0); + let _x = vec.get(0); +} + +#[test(should_fail_with="push out of bounds")] +fn test_vec_push_out_of_bound() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.push(1); + vec.push(2); +} + +#[test(should_fail_with="extend_from_bounded_vec out of bounds")] +fn test_vec_extend_from_bounded_vec_out_of_bound() { + let mut vec: BoundedVec = BoundedVec::new(0); + + let mut another_vec: BoundedVec = BoundedVec::new(0); + another_vec.extend_from_array([1, 2, 3]); + + vec.extend_from_bounded_vec(another_vec); +} + +#[test(should_fail_with="extend_from_bounded_vec out of bounds")] +fn test_vec_extend_from_bounded_vec_twice_out_of_bound() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.extend_from_array([1, 2]); + + let mut another_vec: BoundedVec = BoundedVec::new(0); + another_vec.push(3); + + vec.extend_from_bounded_vec(another_vec); +} + +#[test] +fn test_vec_any() { + let mut vec: BoundedVec = BoundedVec::new(0); + vec.extend_from_array([2, 4, 6]); + assert(vec.any(|v| v == 2) == true); + assert(vec.any(|v| v == 4) == true); + assert(vec.any(|v| v == 6) == true); + assert(vec.any(|v| v == 3) == false); +} + +#[test] +fn test_vec_any_not_default() { + let default_value = 1; + let mut vec: BoundedVec = BoundedVec::new(default_value); + vec.extend_from_array([2, 4]); + assert(vec.any(|v| v == default_value) == false); +} \ No newline at end of file diff --git a/noir/tooling/bb_abstraction_leaks/build.rs b/noir/tooling/bb_abstraction_leaks/build.rs index 18413f87793..6197f52cb4b 100644 --- a/noir/tooling/bb_abstraction_leaks/build.rs +++ b/noir/tooling/bb_abstraction_leaks/build.rs @@ -10,7 +10,7 @@ use const_format::formatcp; const USERNAME: &str = "AztecProtocol"; const REPO: &str = "aztec-packages"; -const VERSION: &str = "0.19.0"; +const VERSION: &str = "0.21.0"; const TAG: &str = formatcp!("aztec-packages-v{}", VERSION); const API_URL: &str = diff --git a/noir/tooling/noir_js_backend_barretenberg/package.json b/noir/tooling/noir_js_backend_barretenberg/package.json index cd2a6354ac4..a0123883efd 100644 --- a/noir/tooling/noir_js_backend_barretenberg/package.json +++ b/noir/tooling/noir_js_backend_barretenberg/package.json @@ -42,7 +42,7 @@ "lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0" }, "dependencies": { - "@aztec/bb.js": "0.19.0", + "@aztec/bb.js": "0.21.0", "@noir-lang/types": "workspace:*", "fflate": "^0.8.0" }, diff --git a/noir/yarn.lock b/noir/yarn.lock index db3f493bc62..743068f1907 100644 --- a/noir/yarn.lock +++ b/noir/yarn.lock @@ -235,9 +235,9 @@ __metadata: languageName: node linkType: hard -"@aztec/bb.js@npm:0.19.0": - version: 0.19.0 - resolution: "@aztec/bb.js@npm:0.19.0" +"@aztec/bb.js@npm:0.21.0": + version: 0.21.0 + resolution: "@aztec/bb.js@npm:0.21.0" dependencies: comlink: ^4.4.1 commander: ^10.0.1 @@ -245,7 +245,7 @@ __metadata: tslib: ^2.4.0 bin: bb.js: dest/node/main.js - checksum: c78c22c3b8c43e0010a43145f973489aa7da9fcf0b8527884107f1f34ac3ca5f5d4ab087d74ce50cb75d6dbaef88bfc693e23745282faa30b81dc78481c65874 + checksum: a0fb97476f52025f3c31b7a5e890966ac375ed47c5cfd3434f5c3e4265af3c7566a162f37d6c56f394f44bfe4ba67e5002b7c5998ecc4f6abe70e04f5b8abe34 languageName: node linkType: hard @@ -4435,7 +4435,7 @@ __metadata: version: 0.0.0-use.local resolution: "@noir-lang/backend_barretenberg@workspace:tooling/noir_js_backend_barretenberg" dependencies: - "@aztec/bb.js": 0.19.0 + "@aztec/bb.js": 0.21.0 "@noir-lang/types": "workspace:*" "@types/node": ^20.6.2 "@types/prettier": ^3 diff --git a/yarn-project/aztec-nr/authwit/src/entrypoint.nr b/yarn-project/aztec-nr/authwit/src/entrypoint.nr index 05ca66240f0..98987d49e36 100644 --- a/yarn-project/aztec-nr/authwit/src/entrypoint.nr +++ b/yarn-project/aztec-nr/authwit/src/entrypoint.nr @@ -1,5 +1,4 @@ use dep::aztec::abi; -use dep::aztec::types::vec::BoundedVec; use dep::aztec::context::PrivateContext; use dep::aztec::protocol_types::{ abis::{ @@ -66,7 +65,7 @@ impl Serialize for EntrypointPayload { fn serialize(self) -> [Field; ENTRYPOINT_PAYLOAD_SIZE] { let mut fields: BoundedVec = BoundedVec::new(0); for call in self.function_calls { - fields.push_array(call.serialize()); + fields.extend_from_array(call.serialize()); } fields.push(self.nonce); fields.storage diff --git a/yarn-project/aztec-nr/aztec/src/context.nr b/yarn-project/aztec-nr/aztec/src/context.nr index f2ef5dfc511..2766304193e 100644 --- a/yarn-project/aztec-nr/aztec/src/context.nr +++ b/yarn-project/aztec-nr/aztec/src/context.nr @@ -14,7 +14,6 @@ use crate::{ header::get_header_at, nullifier_key::{get_nullifier_key_pair, NullifierKeyPair}, }, - types::vec::BoundedVec, utils::Reader, }; use dep::protocol_types::{ diff --git a/yarn-project/aztec-nr/aztec/src/lib.nr b/yarn-project/aztec-nr/aztec/src/lib.nr index 9bf7bf42c8f..7a8531601c4 100644 --- a/yarn-project/aztec-nr/aztec/src/lib.nr +++ b/yarn-project/aztec-nr/aztec/src/lib.nr @@ -8,6 +8,5 @@ mod messaging; mod note; mod oracle; mod state_vars; -mod types; mod utils; use dep::protocol_types; diff --git a/yarn-project/aztec-nr/aztec/src/note/note_getter.nr b/yarn-project/aztec-nr/aztec/src/note/note_getter.nr index a442aad9f83..2200ed3cb58 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_getter.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_getter.nr @@ -17,7 +17,6 @@ use crate::note::{ utils::compute_note_hash_for_read_or_nullify, }; use crate::oracle; -use crate::types::vec::BoundedVec; fn check_note_header( context: PrivateContext, diff --git a/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr b/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr index 611ac239a34..bec2aa7f001 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_getter_options.nr @@ -1,5 +1,4 @@ use dep::std::option::Option; -use crate::types::vec::BoundedVec; use dep::protocol_types::{ constants::MAX_READ_REQUESTS_PER_CALL, traits::Deserialize, diff --git a/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr b/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr index 5677b33f429..a935f63f791 100644 --- a/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr +++ b/yarn-project/aztec-nr/aztec/src/note/note_viewer_options.nr @@ -1,6 +1,5 @@ use dep::std::option::Option; use crate::note::note_getter_options::{Select, Sort, Comparator, NoteStatus}; -use crate::types::vec::BoundedVec; use dep::protocol_types::{ constants::MAX_NOTES_PER_PAGE, traits::Deserialize, diff --git a/yarn-project/aztec-nr/aztec/src/types.nr b/yarn-project/aztec-nr/aztec/src/types.nr deleted file mode 100644 index ae46c9e0c88..00000000000 --- a/yarn-project/aztec-nr/aztec/src/types.nr +++ /dev/null @@ -1 +0,0 @@ -mod vec; // This can/should be moved out into an official noir library diff --git a/yarn-project/aztec-nr/aztec/src/types/vec.nr b/yarn-project/aztec-nr/aztec/src/types/vec.nr deleted file mode 100644 index 135bbbd53c3..00000000000 --- a/yarn-project/aztec-nr/aztec/src/types/vec.nr +++ /dev/null @@ -1,126 +0,0 @@ -struct BoundedVec { - storage: [T; MaxLen], - len: Field, -} - -impl BoundedVec { - pub fn new(initial_value: T) -> Self { - BoundedVec { storage: [initial_value; MaxLen], len: 0 } - } - - pub fn get(mut self: Self, index: Field) -> T { - assert(index as u64 < self.len as u64); - self.storage[index] - } - - pub fn get_unchecked(mut self: Self, index: Field) -> T { - self.storage[index] - } - - pub fn push(&mut self, elem: T) { - assert(self.len as u64 < MaxLen as u64); - - self.storage[self.len] = elem; - self.len += 1; - } - - pub fn push_array(&mut self, array: [T; Len]) { - let newLen = self.len + array.len(); - assert(newLen as u64 <= MaxLen as u64); - for i in 0..array.len() { - self.storage[self.len + i] = array[i]; - } - self.len = newLen; - } - - pub fn pop(&mut self) -> T { - assert(self.len as u64 > 0); - - let elem = self.storage[self.len - 1]; - self.len -= 1; - elem - } - - pub fn any(self, predicate: fn[Env](T) -> bool) -> bool { - let mut ret = false; - let mut exceeded_len = false; - for i in 0..MaxLen { - exceeded_len |= i == self.len; - if (!exceeded_len) { - ret |= predicate(self.storage[i]); - } - } - ret - } -} - -#[test] -fn test_vec_push_pop() { - let mut vec: BoundedVec = BoundedVec::new(0); - assert(vec.len == 0); - vec.push(2); - assert(vec.len == 1); - vec.push(4); - assert(vec.len == 2); - vec.push(6); - assert(vec.len == 3); - let x = vec.pop(); - assert(x == 6); - assert(vec.len == 2); - assert(vec.get(0) == 2); - assert(vec.get(1) == 4); -} - -#[test] -fn test_vec_push_array() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2, 4]); - assert(vec.len == 2); - assert(vec.get(0) == 2); - assert(vec.get(1) == 4); -} - -#[test(should_fail)] -fn test_vec_get_out_of_bound() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2, 4]); - let _x = vec.get(2); -} - -#[test(should_fail)] -fn test_vec_get_not_declared() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2]); - let _x = vec.get(1); -} - -#[test(should_fail)] -fn test_vec_get_uninitialized() { - let mut vec: BoundedVec = BoundedVec::new(0); - let _x = vec.get(0); -} - -#[test(should_fail)] -fn test_vec_push_overflow() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push(1); - vec.push(2); -} - -#[test] -fn test_vec_any() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2, 4, 6]); - assert(vec.any(|v| v == 2) == true); - assert(vec.any(|v| v == 4) == true); - assert(vec.any(|v| v == 6) == true); - assert(vec.any(|v| v == 3) == false); -} - -#[test] -fn test_vec_any_not_default() { - let default_value = 1; - let mut vec: BoundedVec = BoundedVec::new(default_value); - vec.push_array([2, 4]); - assert(vec.any(|v| v == default_value) == false); -} diff --git a/yarn-project/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr b/yarn-project/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr index faef2015a90..6226024e39f 100644 --- a/yarn-project/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/schnorr_hardcoded_account_contract/src/main.nr @@ -5,7 +5,6 @@ contract SchnorrHardcodedAccount { use dep::aztec::{ abi::{ PrivateCircuitPublicInputs, PrivateContextInputs, Hasher }, context::PrivateContext, - types::vec::BoundedVec, }; use dep::authwit:: { diff --git a/yarn-project/noir-contracts/contracts/test_contract/src/main.nr b/yarn-project/noir-contracts/contracts/test_contract/src/main.nr index 14d7a7f6ee6..791016b7a8d 100644 --- a/yarn-project/noir-contracts/contracts/test_contract/src/main.nr +++ b/yarn-project/noir-contracts/contracts/test_contract/src/main.nr @@ -41,7 +41,6 @@ contract Test { }, state_vars::immutable_singleton::ImmutableSingleton, log::emit_unencrypted_log_from_private, - types::vec::BoundedVec, }; use dep::token_portal_content_hash_lib::{get_mint_private_content_hash, get_mint_public_content_hash}; use dep::field_note::field_note::FieldNote; @@ -193,7 +192,7 @@ contract Test { args.push(a_field); args.push(a_bool as Field); args.push(a_number as Field); - args.push_array(an_array); + args.extend_from_array(an_array); args.push(a_struct.amount); args.push(a_struct.secret_hash); args.push(a_deep_struct.a_field); diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr index d6a12b2a411..9b875910712 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/common.nr @@ -42,7 +42,6 @@ use dep::types::{ array_to_bounded_vec, validate_array, }, - bounded_vec::BoundedVec, }, traits::{is_empty, is_empty_array}, }; @@ -50,7 +49,7 @@ use dep::types::{ pub fn validate_arrays(app_public_inputs: PrivateCircuitPublicInputs) { // Each of the following arrays is expected to be zero-padded. // In addition, some of the following arrays (new_commitments, etc...) are passed - // to push_array_to_array() routines which rely on the passed arrays to be well-formed. + // to extend_from_array_to_array() routines which rely on the passed arrays to be well-formed. validate_array(app_public_inputs.return_values); validate_array(app_public_inputs.read_requests); @@ -197,7 +196,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern ) } } - public_inputs.end.read_requests.push_vec(siloed_read_requests); + public_inputs.end.read_requests.extend_from_bounded_vec(siloed_read_requests); // Nullifier key validation requests. for i in 0..MAX_NULLIFIER_KEY_VALIDATION_REQUESTS_PER_CALL { @@ -228,7 +227,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern ); } } - public_inputs.end.new_nullifiers.push_vec(siloed_new_nullifiers); + public_inputs.end.new_nullifiers.extend_from_bounded_vec(siloed_new_nullifiers); // commitments let mut siloed_new_commitments: BoundedVec = BoundedVec::new(SideEffect::empty()); @@ -240,7 +239,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern ); } } - public_inputs.end.new_commitments.push_vec(siloed_new_commitments); + public_inputs.end.new_commitments.extend_from_bounded_vec(siloed_new_commitments); // Call stacks // Private call stack. @@ -250,7 +249,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern private_call_public_inputs.private_call_stack_hashes, private_call ); - public_inputs.end.private_call_stack.push_vec(private_call_stack); + public_inputs.end.private_call_stack.extend_from_bounded_vec(private_call_stack); // Public call stack. let public_call_stack = array_to_bounded_vec(private_call.public_call_stack); validate_call_requests( @@ -258,7 +257,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern private_call_public_inputs.public_call_stack_hashes, private_call ); - public_inputs.end.public_call_stack.push_vec(public_call_stack); + public_inputs.end.public_call_stack.extend_from_bounded_vec(public_call_stack); // new l2 to l1 messages let portal_contract_address = private_call.portal_contract_address; @@ -277,7 +276,7 @@ pub fn update_end_values(private_call: PrivateCallData, public_inputs: &mut Kern new_l2_to_l1_msgs_to_insert.push(new_l2_to_l1_msgs) } } - public_inputs.end.new_l2_to_l1_msgs.push_vec(new_l2_to_l1_msgs_to_insert); + public_inputs.end.new_l2_to_l1_msgs.extend_from_bounded_vec(new_l2_to_l1_msgs_to_insert); // logs hashes // See the following thread if not clear: diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr index 79eb6909614..798bcf16f9c 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_init.nr @@ -264,7 +264,7 @@ mod tests { fn input_validation_malformed_arrays_return_values() { let mut builder = PrivateKernelInitInputsBuilder::new_constructor(); - builder.private_call.public_inputs.return_values.push_array([0, 9123]); + builder.private_call.public_inputs.return_values.extend_from_array([0, 9123]); builder.failed(); } @@ -273,7 +273,7 @@ mod tests { fn input_validation_malformed_arrays_read_requests() { let mut builder = PrivateKernelInitInputsBuilder::new_constructor(); - builder.private_call.public_inputs.read_requests.push_array( + builder.private_call.public_inputs.read_requests.extend_from_array( [ SideEffect { value: 0, counter: 0 }, SideEffect { value: 9123, counter: 1 } @@ -287,7 +287,7 @@ mod tests { fn input_validation_malformed_arrays_commitments() { let mut builder = PrivateKernelInitInputsBuilder::new_constructor(); - builder.private_call.public_inputs.new_commitments.push_array( + builder.private_call.public_inputs.new_commitments.extend_from_array( [ SideEffect { value: 0, counter: 0 }, SideEffect { value: 9123, counter: 1 } @@ -301,7 +301,7 @@ mod tests { fn input_validation_malformed_arrays_nullifiers() { let mut builder = PrivateKernelInitInputsBuilder::new_constructor(); - builder.private_call.public_inputs.new_nullifiers.push_array( + builder.private_call.public_inputs.new_nullifiers.extend_from_array( [ SideEffectLinkedToNoteHash { value: 0, note_hash: 0, counter: 0 }, SideEffectLinkedToNoteHash { value: 9123, note_hash: 0, counter: 1 } @@ -315,7 +315,7 @@ mod tests { fn input_validation_malformed_arrays_private_call_stack() { let mut builder = PrivateKernelInitInputsBuilder::new_constructor(); - builder.private_call.public_inputs.private_call_stack_hashes.push_array([0, 9123]); + builder.private_call.public_inputs.private_call_stack_hashes.extend_from_array([0, 9123]); builder.failed(); } @@ -324,7 +324,7 @@ mod tests { fn input_validation_malformed_arrays_public_call_stack() { let mut builder = PrivateKernelInitInputsBuilder::new_constructor(); - builder.private_call.public_inputs.public_call_stack_hashes.push_array([0, 9123]); + builder.private_call.public_inputs.public_call_stack_hashes.extend_from_array([0, 9123]); builder.failed(); } @@ -333,7 +333,7 @@ mod tests { fn input_validation_malformed_arrays_new_l2_to_l1_msgs() { let mut builder = PrivateKernelInitInputsBuilder::new_constructor(); - builder.private_call.public_inputs.new_l2_to_l1_msgs.push_array([0, 9123]); + builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array([0, 9123]); builder.failed(); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr index b6329348cb4..13144419983 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_inner.nr @@ -97,7 +97,6 @@ mod tests { hash::compute_logs_hash, utils::{ arrays::array_length, - bounded_vec::BoundedVec, }, }; @@ -441,7 +440,7 @@ mod tests { fn input_validation_malformed_arrays_return_values() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.return_values.push_array([0, 553]); + builder.private_call.public_inputs.return_values.extend_from_array([0, 553]); builder.failed(); } @@ -450,7 +449,7 @@ mod tests { fn input_validation_malformed_arrays_read_requests() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.read_requests.push_array( + builder.private_call.public_inputs.read_requests.extend_from_array( [ SideEffect { value: 0, counter: 0 }, SideEffect { value: 9123, counter: 1 } @@ -464,7 +463,7 @@ mod tests { fn input_validation_malformed_arrays_commitments() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.new_commitments.push_array( + builder.private_call.public_inputs.new_commitments.extend_from_array( [ SideEffect { value: 0, counter: 0 }, SideEffect { value: 9123, counter: 1 } @@ -478,7 +477,7 @@ mod tests { fn input_validation_malformed_arrays_nullifiers() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.new_nullifiers.push_array( + builder.private_call.public_inputs.new_nullifiers.extend_from_array( [ SideEffectLinkedToNoteHash { value: 0, note_hash: 0, counter: 0 }, SideEffectLinkedToNoteHash { value: 12, note_hash: 0, counter: 1 } @@ -492,7 +491,7 @@ mod tests { fn input_validation_malformed_arrays_private_call_stack() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.private_call_stack_hashes.push_array([0, 888]); + builder.private_call.public_inputs.private_call_stack_hashes.extend_from_array([0, 888]); builder.failed(); } @@ -501,7 +500,7 @@ mod tests { fn input_validation_malformed_arrays_public_call_stack() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.public_call_stack_hashes.push_array([0, 888]); + builder.private_call.public_inputs.public_call_stack_hashes.extend_from_array([0, 888]); builder.failed(); } @@ -510,12 +509,12 @@ mod tests { fn input_validation_malformed_arrays_new_l2_to_l1_msgs() { let mut builder = PrivateKernelInnerInputsBuilder::new(); - builder.private_call.public_inputs.new_l2_to_l1_msgs.push_array([0, 888]); + builder.private_call.public_inputs.new_l2_to_l1_msgs.extend_from_array([0, 888]); builder.failed(); } - #[test(should_fail_with = "push_vec out of bounds")] + #[test(should_fail_with = "extend_from_bounded_vec out of bounds")] fn private_kernel_should_fail_if_aggregating_too_many_commitments() { let mut builder = PrivateKernelInnerInputsBuilder::new(); @@ -530,7 +529,7 @@ mod tests { counter: i as u32, }; } - builder.previous_kernel.end.new_commitments.push_array(full_new_commitments); + builder.previous_kernel.end.new_commitments.extend_from_array(full_new_commitments); builder.failed(); } diff --git a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_ordering.nr b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_ordering.nr index c937d43d832..6c6496b7ad5 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_ordering.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/private-kernel-lib/src/private_kernel_ordering.nr @@ -28,7 +28,6 @@ use dep::types::{ }, utils::{ arrays::{array_length, array_eq}, - bounded_vec::BoundedVec, }, traits::{Empty, is_empty} }; @@ -236,7 +235,6 @@ mod tests { tests::previous_kernel_data_builder::PreviousKernelDataBuilder, utils::{ arrays::{array_eq, array_length}, - bounded_vec::BoundedVec, }, traits::{Empty, is_empty, is_empty_array} }; diff --git a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr index f197513228f..87929586626 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/common.nr @@ -28,7 +28,6 @@ use dep::types::{ hash::{silo_commitment, silo_nullifier, compute_l2_to_l1_hash, accumulate_sha256}, utils::{ arrays::{array_length, array_to_bounded_vec}, - bounded_vec::BoundedVec, }, traits::is_empty_array }; @@ -138,7 +137,7 @@ pub fn update_public_end_values(public_call: PublicCallData, circuit_outputs: &m let public_call_requests = array_to_bounded_vec(public_call.public_call_stack); let hashes = public_call.call_stack_item.public_inputs.public_call_stack_hashes; validate_call_requests(public_call_requests, hashes, public_call); - circuit_outputs.end.public_call_stack.push_vec(public_call_requests); + circuit_outputs.end.public_call_stack.extend_from_bounded_vec(public_call_requests); propagate_new_nullifiers(public_call, circuit_outputs); propagate_new_commitments(public_call, circuit_outputs); @@ -171,7 +170,7 @@ fn propagate_valid_public_data_update_requests( public_data_update_requests.push(public_data_update_request); } } - circuit_outputs.end.public_data_update_requests.push_vec(public_data_update_requests); + circuit_outputs.end.public_data_update_requests.extend_from_bounded_vec(public_data_update_requests); } fn propagate_valid_public_data_reads(public_call: PublicCallData, circuit_outputs: &mut KernelCircuitPublicInputsBuilder) { @@ -190,7 +189,7 @@ fn propagate_valid_public_data_reads(public_call: PublicCallData, circuit_output public_data_reads.push(public_data_read); } } - circuit_outputs.end.public_data_reads.push_vec(public_data_reads); + circuit_outputs.end.public_data_reads.extend_from_bounded_vec(public_data_reads); } fn propagate_new_commitments(public_call: PublicCallData, circuit_outputs: &mut KernelCircuitPublicInputsBuilder) { @@ -207,7 +206,7 @@ fn propagate_new_commitments(public_call: PublicCallData, circuit_outputs: &mut siloed_new_commitments.push(SideEffect { value: siloed_new_commitment, counter: new_commitments[i].counter }); } } - circuit_outputs.end.new_commitments.push_vec(siloed_new_commitments); + circuit_outputs.end.new_commitments.extend_from_bounded_vec(siloed_new_commitments); } fn propagate_new_nullifiers(public_call: PublicCallData, circuit_outputs: &mut KernelCircuitPublicInputsBuilder) { @@ -230,7 +229,7 @@ fn propagate_new_nullifiers(public_call: PublicCallData, circuit_outputs: &mut K } } - circuit_outputs.end.new_nullifiers.push_vec(siloed_new_nullifiers); + circuit_outputs.end.new_nullifiers.extend_from_bounded_vec(siloed_new_nullifiers); } fn propagate_new_l2_to_l1_messages(public_call: PublicCallData, public_inputs: &mut KernelCircuitPublicInputsBuilder) { @@ -254,7 +253,7 @@ fn propagate_new_l2_to_l1_messages(public_call: PublicCallData, public_inputs: & new_l2_to_l1_msgs_to_insert.push(new_l2_to_l1_msgs) } } - public_inputs.end.new_l2_to_l1_msgs.push_vec(new_l2_to_l1_msgs_to_insert); + public_inputs.end.new_l2_to_l1_msgs.extend_from_bounded_vec(new_l2_to_l1_msgs_to_insert); } /** diff --git a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr index 0cab8070c21..43171da38b3 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_private_previous.nr @@ -85,7 +85,6 @@ mod tests { array_eq, array_length, }, - bounded_vec::BoundedVec, }, }; use dep::types::constants::{ @@ -406,7 +405,7 @@ mod tests { contract_class_id: 78 } ]; - builder.previous_kernel.end.new_contracts.push_array(new_contracts); + builder.previous_kernel.end.new_contracts.extend_from_array(new_contracts); builder.public_call.append_public_call_requests_for_regular_calls(2); let storage = builder.public_call.public_call_stack.storage; diff --git a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_public_previous.nr b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_public_previous.nr index 985690d46b9..5f28c5d8dd7 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_public_previous.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/public-kernel-lib/src/public_kernel_public_previous.nr @@ -180,7 +180,7 @@ mod tests { SideEffect { value: previous[1].value + 1, counter: 3 }, SideEffect { value: previous[1].value + 2, counter: 4 } ]; - builder.public_call.public_inputs.new_commitments.push_array(current); + builder.public_call.public_inputs.new_commitments.extend_from_array(current); let siloed = current.map(|c: SideEffect| silo_commitment(contract_address, c.value)); let new_commitments = [ previous[0], previous[1], SideEffect { value: siloed[0], counter: 3 }, SideEffect { value: siloed[1], counter: 4 } @@ -247,7 +247,7 @@ mod tests { SideEffectLinkedToNoteHash { value: silo_nullifier(contract_address, current.value), note_hash: current.note_hash, counter: current.counter } ); - builder.public_call.public_inputs.new_nullifiers.push_array(current); + builder.public_call.public_inputs.new_nullifiers.extend_from_array(current); // There are 3 nullifiers in the previous kernel. The first one is the tx nullifier. let new_nullifiers = [previous[0], previous[1], previous[2], siloed[0], siloed[1]]; @@ -265,10 +265,10 @@ mod tests { // Setup 1 new l2 to l1 message on the previous kernel. let previous = [12345]; - builder.previous_kernel.end.new_l2_to_l1_msgs.push_array(previous); + builder.previous_kernel.end.new_l2_to_l1_msgs.extend_from_array(previous); // Setup 1 new l2 to l1 message on the current public inputs. let current = [67890]; - builder.public_call.public_inputs.new_l2_to_l1_msgs.push_array(current); + builder.public_call.public_inputs.new_l2_to_l1_msgs.extend_from_array(current); let tx_context = builder.previous_kernel.tx_context; let version = tx_context.version; let chain_id = tx_context.chain_id; diff --git a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr index c6ac3c04df3..d831a4647e6 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/rollup-lib/src/base/base_rollup_inputs.nr @@ -597,7 +597,6 @@ mod tests { abis::side_effect::SideEffect, tests::previous_kernel_data_builder::PreviousKernelDataBuilder, address::{AztecAddress, EthAddress}, - utils::bounded_vec::BoundedVec, utils::uint256::U256, partial_state_reference::PartialStateReference, }; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_accumulated_data.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_accumulated_data.nr index 7ada51b7a52..9e74c0ae103 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_accumulated_data.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/combined_accumulated_data.nr @@ -8,8 +8,7 @@ use crate::{ public_data_update_request::PublicDataUpdateRequest, side_effect::{SideEffect, SideEffectLinkedToNoteHash}, }, - mocked::AggregationObject, - utils::bounded_vec::BoundedVec + mocked::AggregationObject }; use crate::constants::{ MAX_READ_REQUESTS_PER_TX, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr index 466420cd416..0df8915d1a4 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/private_circuit_public_inputs.nr @@ -9,7 +9,6 @@ use crate::{ pedersen_hash, }, header::Header, - utils::bounded_vec::BoundedVec, }; use crate::constants::{ MAX_READ_REQUESTS_PER_CALL, @@ -69,26 +68,26 @@ impl Hash for PrivateCircuitPublicInputs { let mut fields: BoundedVec = BoundedVec::new(0); fields.push(self.call_context.hash()); fields.push(self.args_hash); - fields.push_array(self.return_values); + fields.extend_from_array(self.return_values); for i in 0..MAX_READ_REQUESTS_PER_CALL{ - fields.push_array(self.read_requests[i].serialize()); + fields.extend_from_array(self.read_requests[i].serialize()); } for i in 0..MAX_NEW_COMMITMENTS_PER_CALL{ - fields.push_array(self.new_commitments[i].serialize()); + fields.extend_from_array(self.new_commitments[i].serialize()); } for i in 0..MAX_NEW_NULLIFIERS_PER_CALL{ - fields.push_array(self.new_nullifiers[i].serialize()); + fields.extend_from_array(self.new_nullifiers[i].serialize()); } - fields.push_array(self.private_call_stack_hashes); - fields.push_array(self.public_call_stack_hashes); - fields.push_array(self.new_l2_to_l1_msgs); + fields.extend_from_array(self.private_call_stack_hashes); + fields.extend_from_array(self.public_call_stack_hashes); + fields.extend_from_array(self.new_l2_to_l1_msgs); fields.push(self.end_side_effect_counter as Field); - fields.push_array(self.encrypted_logs_hash); - fields.push_array(self.unencrypted_logs_hash); + fields.extend_from_array(self.encrypted_logs_hash); + fields.extend_from_array(self.unencrypted_logs_hash); fields.push(self.encrypted_log_preimages_length); fields.push(self.unencrypted_log_preimages_length); - fields.push_array(self.historical_header.serialize()); + fields.extend_from_array(self.historical_header.serialize()); fields.push(self.contract_deployment_data.hash()); fields.push(self.chain_id); fields.push(self.version); @@ -102,29 +101,29 @@ impl Hash for PrivateCircuitPublicInputs { impl Serialize for PrivateCircuitPublicInputs { fn serialize(self) -> [Field; PRIVATE_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); - fields.push_array(self.call_context.serialize()); + fields.extend_from_array(self.call_context.serialize()); fields.push(self.args_hash); - fields.push_array(self.return_values); + fields.extend_from_array(self.return_values); for i in 0..MAX_READ_REQUESTS_PER_CALL{ - fields.push_array(self.read_requests[i].serialize()); + fields.extend_from_array(self.read_requests[i].serialize()); } for i in 0..MAX_NEW_COMMITMENTS_PER_CALL{ - fields.push_array(self.new_commitments[i].serialize()); + fields.extend_from_array(self.new_commitments[i].serialize()); } for i in 0..MAX_NEW_NULLIFIERS_PER_CALL{ - fields.push_array(self.new_nullifiers[i].serialize()); + fields.extend_from_array(self.new_nullifiers[i].serialize()); } - fields.push_array(self.private_call_stack_hashes); - fields.push_array(self.public_call_stack_hashes); - fields.push_array(self.new_l2_to_l1_msgs); + fields.extend_from_array(self.private_call_stack_hashes); + fields.extend_from_array(self.public_call_stack_hashes); + fields.extend_from_array(self.new_l2_to_l1_msgs); fields.push(self.end_side_effect_counter as Field); - fields.push_array(self.encrypted_logs_hash); - fields.push_array(self.unencrypted_logs_hash); + fields.extend_from_array(self.encrypted_logs_hash); + fields.extend_from_array(self.unencrypted_logs_hash); fields.push(self.encrypted_log_preimages_length); fields.push(self.unencrypted_log_preimages_length); - fields.push_array(self.historical_header.serialize()); - fields.push_array(self.contract_deployment_data.serialize()); + fields.extend_from_array(self.historical_header.serialize()); + fields.extend_from_array(self.contract_deployment_data.serialize()); fields.push(self.chain_id); fields.push(self.version); diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr index 5da7a1de2ff..6c130e5e65d 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/abis/public_circuit_public_inputs.nr @@ -22,7 +22,6 @@ use crate::{ storage_update_request::StorageUpdateRequest, }, header::Header, - utils::bounded_vec::BoundedVec, }; struct PublicCircuitPublicInputs{ @@ -59,14 +58,14 @@ impl PublicCircuitPublicInputs{ let mut inputs: BoundedVec = BoundedVec::new(0); inputs.push(self.call_context.hash()); inputs.push(self.args_hash); - inputs.push_array(self.return_values); + inputs.extend_from_array(self.return_values); for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { inputs.push(self.contract_storage_update_requests[i].hash()); } for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { inputs.push(self.contract_storage_reads[i].hash()); } - inputs.push_array(self.public_call_stack_hashes); + inputs.extend_from_array(self.public_call_stack_hashes); for i in 0..MAX_NEW_COMMITMENTS_PER_CALL{ inputs.push(self.new_commitments[i].hash()); @@ -74,10 +73,10 @@ impl PublicCircuitPublicInputs{ for i in 0..MAX_NEW_NULLIFIERS_PER_CALL{ inputs.push(self.new_nullifiers[i].hash()); } - inputs.push_array(self.new_l2_to_l1_msgs); - inputs.push_array(self.unencrypted_logs_hash); + inputs.extend_from_array(self.new_l2_to_l1_msgs); + inputs.extend_from_array(self.unencrypted_logs_hash); inputs.push(self.unencrypted_log_preimages_length); - inputs.push_array(self.historical_header.serialize()); + inputs.extend_from_array(self.historical_header.serialize()); inputs.push(self.prover_address.to_field()); assert_eq(inputs.len(), PUBLIC_CIRCUIT_PUBLIC_INPUTS_HASH_INPUT_LENGTH, "Incorrect number of input fields when hashing PublicCircuitPublicInputs"); @@ -87,27 +86,27 @@ impl PublicCircuitPublicInputs{ pub fn serialize(self) -> [Field; PUBLIC_CIRCUIT_PUBLIC_INPUTS_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); - fields.push_array(self.call_context.serialize()); + fields.extend_from_array(self.call_context.serialize()); fields.push(self.args_hash); - fields.push_array(self.return_values); + fields.extend_from_array(self.return_values); for i in 0..MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL { - fields.push_array(self.contract_storage_update_requests[i].serialize()); + fields.extend_from_array(self.contract_storage_update_requests[i].serialize()); } for i in 0..MAX_PUBLIC_DATA_READS_PER_CALL { - fields.push_array(self.contract_storage_reads[i].serialize()); + fields.extend_from_array(self.contract_storage_reads[i].serialize()); } - fields.push_array(self.public_call_stack_hashes); + fields.extend_from_array(self.public_call_stack_hashes); for i in 0..MAX_NEW_COMMITMENTS_PER_CALL{ - fields.push_array(self.new_commitments[i].serialize()); + fields.extend_from_array(self.new_commitments[i].serialize()); } for i in 0..MAX_NEW_NULLIFIERS_PER_CALL{ - fields.push_array(self.new_nullifiers[i].serialize()); + fields.extend_from_array(self.new_nullifiers[i].serialize()); } - fields.push_array(self.new_l2_to_l1_msgs); - fields.push_array(self.unencrypted_logs_hash); + fields.extend_from_array(self.new_l2_to_l1_msgs); + fields.extend_from_array(self.unencrypted_logs_hash); fields.push(self.unencrypted_log_preimages_length); - fields.push_array(self.historical_header.serialize()); + fields.extend_from_array(self.historical_header.serialize()); fields.push(self.prover_address.to_field()); fields.storage } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr index bafa08de6cc..ab6c9f260c1 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/hash.nr @@ -6,7 +6,6 @@ use crate::abis::new_contract_data::NewContractData as ContractLeafPreimage; use crate::abis::function_data::FunctionData; use crate::abis::side_effect::{SideEffect}; use crate::utils::uint256::U256; -use crate::utils::bounded_vec::BoundedVec; use crate::constants::{ ARGS_HASH_CHUNK_COUNT, ARGS_HASH_CHUNK_LENGTH, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr index b838c453480..9e081cab674 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/header.nr @@ -22,7 +22,6 @@ use crate::{ traits::Empty, utils::{ arr_copy_slice, - bounded_vec::BoundedVec, }, }; @@ -40,10 +39,10 @@ impl Header { pub fn serialize(self) -> [Field; HEADER_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); - fields.push_array(self.last_archive.serialize()); - fields.push_array(self.body_hash); - fields.push_array(self.state.serialize()); - fields.push_array(self.global_variables.serialize()); + fields.extend_from_array(self.last_archive.serialize()); + fields.extend_from_array(self.body_hash); + fields.extend_from_array(self.state.serialize()); + fields.extend_from_array(self.global_variables.serialize()); fields.storage } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr index ea16db7d032..bb3c517551e 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/state_reference.nr @@ -10,7 +10,6 @@ use crate::{ traits::Empty, utils::{ arr_copy_slice, - bounded_vec::BoundedVec, }, }; @@ -30,8 +29,8 @@ impl StateReference { fn serialize(self) -> [Field; STATE_REFERENCE_LENGTH] { let mut fields: BoundedVec = BoundedVec::new(0); - fields.push_array(self.l1_to_l2_message_tree.serialize()); - fields.push_array(self.partial.serialize()); + fields.extend_from_array(self.l1_to_l2_message_tree.serialize()); + fields.extend_from_array(self.partial.serialize()); fields.storage } diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr index dacb83e2707..a77ddd9b45f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/fixtures/read_requests.nr @@ -3,7 +3,6 @@ use crate::abis::{ side_effect::SideEffect, }; use crate::tests::fixtures; -use crate::utils::bounded_vec::BoundedVec; use crate::constants::{ MAX_READ_REQUESTS_PER_CALL, }; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_call_data_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_call_data_builder.nr index cdedfa676ad..f922026211f 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_call_data_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_call_data_builder.nr @@ -21,9 +21,6 @@ use crate::{ transaction::{ request::TxRequest, }, - utils::{ - bounded_vec::BoundedVec, - }, }; use crate::constants::{ MAX_PRIVATE_CALL_STACK_LENGTH_PER_CALL, @@ -114,14 +111,14 @@ impl PrivateCallDataBuilder { pub fn append_private_call_requests(&mut self, num_requests: Field, is_delegate_call: bool) { let (hashes, call_requests) = self.generate_call_requests(self.private_call_stack, num_requests, is_delegate_call); - self.public_inputs.private_call_stack_hashes.push_vec(hashes); - self.private_call_stack.push_vec(call_requests); + self.public_inputs.private_call_stack_hashes.extend_from_bounded_vec(hashes); + self.private_call_stack.extend_from_bounded_vec(call_requests); } pub fn append_public_call_requests(&mut self, num_requests: Field, is_delegate_call: bool) { let (hashes, call_requests) = self.generate_call_requests(self.public_call_stack, num_requests, is_delegate_call); - self.public_inputs.public_call_stack_hashes.push_vec(hashes); - self.public_call_stack.push_vec(call_requests); + self.public_inputs.public_call_stack_hashes.extend_from_bounded_vec(hashes); + self.public_call_stack.extend_from_bounded_vec(call_requests); } fn generate_call_requests( @@ -162,14 +159,14 @@ impl PrivateCallDataBuilder { pub fn append_read_requests(&mut self, num_read_requests: Field) { let (read_requests, read_request_membership_witnesses) = fixtures::read_requests::generate_read_requests(num_read_requests); - self.public_inputs.read_requests.push_vec(read_requests); - self.read_request_membership_witnesses.push_vec(read_request_membership_witnesses); + self.public_inputs.read_requests.extend_from_bounded_vec(read_requests); + self.read_request_membership_witnesses.extend_from_bounded_vec(read_request_membership_witnesses); } pub fn append_transient_read_requests(&mut self, num_read_requests: Field) { let (read_requests, read_request_membership_witnesses) = fixtures::read_requests::generate_transient_read_requests(num_read_requests); - self.public_inputs.read_requests.push_vec(read_requests); - self.read_request_membership_witnesses.push_vec(read_request_membership_witnesses); + self.public_inputs.read_requests.extend_from_bounded_vec(read_requests); + self.read_request_membership_witnesses.extend_from_bounded_vec(read_request_membership_witnesses); } pub fn set_encrypted_logs(&mut self, hash: [Field; NUM_FIELDS_PER_SHA256], preimages_length: Field) { diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr index 9ea565e9166..46196b43b4a 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/private_circuit_public_inputs_builder.nr @@ -13,7 +13,6 @@ use crate::{ fixtures, testing_harness::build_contract_deployment_data, }, - utils::bounded_vec::BoundedVec, }; use crate::constants::{ MAX_READ_REQUESTS_PER_CALL, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr index a9f85427c66..48dd0bb62e1 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_call_data_builder.nr @@ -17,7 +17,6 @@ use crate::{ fixtures, public_circuit_public_inputs_builder::PublicCircuitPublicInputsBuilder, }, - utils::bounded_vec::BoundedVec, }; use crate::constants::{ MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr index e266a8e34ee..41f2102a051 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/tests/public_circuit_public_inputs_builder.nr @@ -11,7 +11,6 @@ use crate::{ }, header::Header, tests::fixtures, - utils::bounded_vec::BoundedVec, }; use crate::constants::{ MAX_NEW_COMMITMENTS_PER_CALL, diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr index 068a027f7a7..f4c2b212cc2 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils.nr @@ -3,7 +3,6 @@ // Reducing the size of this package would be welcome. mod arrays; -mod bounded_vec; mod field; mod uint256; diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr index 239867b05e0..609071c4d84 100644 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr +++ b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/arrays.nr @@ -1,6 +1,5 @@ use dep::std::array; use dep::std::cmp::Eq; -use crate::utils::bounded_vec::BoundedVec; use crate::traits::{Empty, is_empty}; pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec where T: Empty + Eq { diff --git a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/bounded_vec.nr b/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/bounded_vec.nr deleted file mode 100644 index e9aa91c26de..00000000000 --- a/yarn-project/noir-protocol-circuits/src/crates/types/src/utils/bounded_vec.nr +++ /dev/null @@ -1,194 +0,0 @@ -struct BoundedVec { - storage: [T; MaxLen], - // TODO: change this to return a u64 as Noir now - // uses u64 for indexing - len: Field, - empty_value: T, -} - -impl BoundedVec { - pub fn new(initial_value: T) -> Self { - BoundedVec { storage: [initial_value; MaxLen], len: 0, empty_value: initial_value } - } - - pub fn get(mut self: Self, index: Field) -> T { - assert(index as u64 < self.len as u64); - self.storage[index] - } - - pub fn get_unchecked(mut self: Self, index: Field) -> T { - self.storage[index] - } - - pub fn push(&mut self, elem: T) { - assert(self.len as u64 < MaxLen as u64, "push out of bounds"); - - self.storage[self.len] = elem; - self.len += 1; - } - - pub fn len(self) -> Field { - self.len - } - - pub fn max_len(_self: BoundedVec) -> Field { - MaxLen - } - - // This is a intermediate method, while we don't have an - // .extend method - pub fn storage(self) -> [T; MaxLen] { - self.storage - } - - pub fn push_array(&mut self, array: [T; Len]) { - let new_len = self.len + array.len(); - assert(new_len as u64 <= MaxLen as u64, "push_array out of bounds"); - for i in 0..array.len() { - self.storage[self.len + i] = array[i]; - } - self.len = new_len; - } - - pub fn push_vec(&mut self, vec: BoundedVec) { - let append_len = vec.len(); - let new_len = self.len + append_len; - assert(new_len as u64 <= MaxLen as u64, "push_vec out of bounds"); - - let mut exceeded_len = false; - for i in 0..Len { - exceeded_len |= i == append_len; - if !exceeded_len { - self.storage[self.len + (i as Field)] = vec.get_unchecked(i as Field); - } - } - self.len = new_len; - } - - pub fn pop(&mut self) -> T { - assert(self.len as u64 > 0); - self.len -= 1; - - let elem = self.storage[self.len]; - self.storage[self.len] = self.empty_value; - elem - } - - pub fn any(self, predicate: fn[Env](T) -> bool) -> bool { - let mut ret = false; - let mut exceeded_len = false; - for i in 0..MaxLen { - exceeded_len |= i == self.len; - if (!exceeded_len) { - ret |= predicate(self.storage[i]); - } - } - ret - } -} - -#[test] -fn test_vec_push_pop() { - let mut vec: BoundedVec = BoundedVec::new(0); - assert(vec.len == 0); - vec.push(2); - assert(vec.len == 1); - vec.push(4); - assert(vec.len == 2); - vec.push(6); - assert(vec.len == 3); - let x = vec.pop(); - assert(x == 6); - assert(vec.len == 2); - assert(vec.get(0) == 2); - assert(vec.get(1) == 4); -} - -#[test] -fn test_vec_push_array() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2, 4]); - assert(vec.len == 2); - assert(vec.get(0) == 2); - assert(vec.get(1) == 4); -} - -#[test(should_fail_with="push_array out of bounds")] -fn test_vec_push_array_out_of_bound() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2, 4, 6]); -} - -#[test(should_fail_with="push_array out of bounds")] -fn test_vec_push_array_twice_out_of_bound() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2]); - assert(vec.len == 1); - vec.push_array([4, 6]); -} - -#[test(should_fail)] -fn test_vec_get_out_of_bound() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2, 4]); - let _x = vec.get(2); -} - -#[test(should_fail)] -fn test_vec_get_not_declared() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2]); - let _x = vec.get(1); -} - -#[test(should_fail)] -fn test_vec_get_uninitialized() { - let mut vec: BoundedVec = BoundedVec::new(0); - let _x = vec.get(0); -} - -#[test(should_fail_with="push out of bounds")] -fn test_vec_push_out_of_bound() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push(1); - vec.push(2); -} - -#[test(should_fail_with="push_vec out of bounds")] -fn test_vec_push_vec_out_of_bound() { - let mut vec: BoundedVec = BoundedVec::new(0); - - let mut another_vec: BoundedVec = BoundedVec::new(0); - another_vec.push_array([1, 2, 3]); - - vec.push_vec(another_vec); -} - -#[test(should_fail_with="push_vec out of bounds")] -fn test_vec_push_vec_twice_out_of_bound() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([1, 2]); - - let mut another_vec: BoundedVec = BoundedVec::new(0); - another_vec.push(3); - - vec.push_vec(another_vec); -} - -#[test] -fn test_vec_any() { - let mut vec: BoundedVec = BoundedVec::new(0); - vec.push_array([2, 4, 6]); - assert(vec.any(|v| v == 2) == true); - assert(vec.any(|v| v == 4) == true); - assert(vec.any(|v| v == 6) == true); - assert(vec.any(|v| v == 3) == false); -} - -#[test] -fn test_vec_any_not_default() { - let default_value = 1; - let mut vec: BoundedVec = BoundedVec::new(default_value); - vec.push_array([2, 4]); - assert(vec.any(|v| v == default_value) == false); -} diff --git a/yarn-project/yarn.lock b/yarn-project/yarn.lock index 06235a30e20..472b7df6b99 100644 --- a/yarn-project/yarn.lock +++ b/yarn-project/yarn.lock @@ -2761,7 +2761,7 @@ __metadata: version: 0.0.0-use.local resolution: "@noir-lang/backend_barretenberg@portal:../noir/packages/backend_barretenberg::locator=%40aztec%2Faztec3-packages%40workspace%3A." dependencies: - "@aztec/bb.js": 0.19.0 + "@aztec/bb.js": 0.21.0 "@noir-lang/types": 0.23.0 fflate: ^0.8.0 languageName: node