Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into acvm-0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
phated authored May 22, 2023
2 parents 3e7409d + f6134b7 commit 4a8099a
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 25 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## [0.2.0](https://github.com/noir-lang/acvm-backend-barretenberg/compare/v0.1.2...v0.2.0) (2023-05-22)


### ⚠ BREAKING CHANGES

* Update to acvm 0.12.0 ([#165](https://github.com/noir-lang/acvm-backend-barretenberg/issues/165))
* Add serialization logic for RAM and ROM opcodes ([#153](https://github.com/noir-lang/acvm-backend-barretenberg/issues/153))

### Features

* Add serde to `ConstraintSystem` types ([#196](https://github.com/noir-lang/acvm-backend-barretenberg/issues/196)) ([4c04a79](https://github.com/noir-lang/acvm-backend-barretenberg/commit/4c04a79e6d2b0115f3b4526c60f9f7dae8b464ae))
* Add serialization logic for RAM and ROM opcodes ([#153](https://github.com/noir-lang/acvm-backend-barretenberg/issues/153)) ([3d3847d](https://github.com/noir-lang/acvm-backend-barretenberg/commit/3d3847de70e74a8f65c64e165ad15ae3d31f5350))
* Update to acvm 0.12.0 ([#165](https://github.com/noir-lang/acvm-backend-barretenberg/issues/165)) ([d613c79](https://github.com/noir-lang/acvm-backend-barretenberg/commit/d613c79584a599f4adbd11d2ce3b61403c185b73))

## [0.1.2](https://github.com/noir-lang/acvm-backend-barretenberg/compare/v0.1.1...v0.1.2) (2023-05-11)


Expand Down
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "acvm-backend-barretenberg"
description = "An ACVM backend which allows proving/verifying ACIR circuits against Aztec Lab's Barretenberg library."
version = "0.1.2"
version = "0.2.0"
authors = ["The Noir Team <[email protected]>"]
edition = "2021"
rust-version = "1.66"
Expand All @@ -15,6 +15,7 @@ bincode = "1.3.3"
bytesize = "1.2"
reqwest = { version = "0.11.16", default-features = false, features = ["rustls-tls"] }
serde = { version = "1.0.136", features = ["derive"] }
serde-big-array = "0.5.1"
thiserror = "1.0.21"

# Native
Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
commonArgs = {
pname = "acvm-backend-barretenberg";
# x-release-please-start-version
version = "0.1.2";
version = "0.2.0";
# x-release-please-end

src = pkgs.lib.cleanSourceWith {
Expand Down
38 changes: 22 additions & 16 deletions src/barretenberg_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ use acvm::acir::circuit::{Circuit, Opcode};
use acvm::acir::native_types::Expression;
use acvm::acir::BlackBoxFunc;
use acvm::FieldElement;
use serde::{Deserialize, Serialize};
use serde_big_array::BigArray;

use crate::Error;

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
pub(crate) struct Assignments(Vec<FieldElement>);

// This is a separate impl so the constructor can get the wasm_bindgen macro in the future
Expand Down Expand Up @@ -51,7 +53,7 @@ impl From<Vec<FieldElement>> for Assignments {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct Constraint {
pub(crate) a: i32,
pub(crate) b: i32,
Expand Down Expand Up @@ -112,7 +114,7 @@ impl Constraint {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct RangeConstraint {
pub(crate) a: i32,
pub(crate) num_bits: i32,
Expand All @@ -128,9 +130,11 @@ impl RangeConstraint {
buffer
}
}
#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct EcdsaConstraint {
pub(crate) hashed_message: Vec<i32>,
// Required until Serde adopts const generics: https://github.com/serde-rs/serde/issues/1937
#[serde(with = "BigArray")]
pub(crate) signature: [i32; 64],
pub(crate) public_key_x: [i32; 32],
pub(crate) public_key_y: [i32; 32],
Expand Down Expand Up @@ -170,9 +174,11 @@ impl EcdsaConstraint {
buffer
}
}
#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct SchnorrConstraint {
pub(crate) message: Vec<i32>,
// Required until Serde adopts const generics: https://github.com/serde-rs/serde/issues/1937
#[serde(with = "BigArray")]
pub(crate) signature: [i32; 64],
pub(crate) public_key_x: i32,
pub(crate) public_key_y: i32,
Expand Down Expand Up @@ -202,7 +208,7 @@ impl SchnorrConstraint {
buffer
}
}
#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct ComputeMerkleRootConstraint {
pub(crate) hash_path: Vec<i32>,
pub(crate) leaf: i32,
Expand All @@ -229,7 +235,7 @@ impl ComputeMerkleRootConstraint {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct Sha256Constraint {
pub(crate) inputs: Vec<(i32, i32)>,
pub(crate) result: [i32; 32],
Expand All @@ -255,7 +261,7 @@ impl Sha256Constraint {
buffer
}
}
#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct Blake2sConstraint {
pub(crate) inputs: Vec<(i32, i32)>,
pub(crate) result: [i32; 32],
Expand All @@ -281,7 +287,7 @@ impl Blake2sConstraint {
buffer
}
}
#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct HashToFieldConstraint {
pub(crate) inputs: Vec<(i32, i32)>,
pub(crate) result: i32,
Expand All @@ -304,7 +310,7 @@ impl HashToFieldConstraint {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct Keccak256Constraint {
pub(crate) inputs: Vec<(i32, i32)>,
pub(crate) result: [i32; 32],
Expand All @@ -331,7 +337,7 @@ impl Keccak256Constraint {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct PedersenConstraint {
pub(crate) inputs: Vec<i32>,
pub(crate) result_x: i32,
Expand All @@ -354,7 +360,7 @@ impl PedersenConstraint {
buffer
}
}
#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct FixedBaseScalarMulConstraint {
pub(crate) scalar: i32,
pub(crate) pubkey_x: i32,
Expand All @@ -373,7 +379,7 @@ impl FixedBaseScalarMulConstraint {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct LogicConstraint {
pub(crate) a: i32,
pub(crate) b: i32,
Expand Down Expand Up @@ -415,7 +421,7 @@ impl LogicConstraint {
}
}

#[derive(Clone, Hash, Debug, Default)]
#[derive(Clone, Hash, Debug, Default, Serialize, Deserialize)]
pub(crate) struct ConstraintSystem {
var_num: u32,
public_inputs: Vec<u32>,
Expand Down Expand Up @@ -659,7 +665,7 @@ impl ConstraintSystem {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct MemOpBarretenberg {
pub(crate) is_store: i8,
pub(crate) index: Constraint,
Expand All @@ -677,7 +683,7 @@ impl MemOpBarretenberg {
}
}

#[derive(Clone, Hash, Debug)]
#[derive(Clone, Hash, Debug, Serialize, Deserialize)]
pub(crate) struct BlockConstraint {
pub(crate) init: Vec<Constraint>,
pub(crate) trace: Vec<MemOpBarretenberg>,
Expand Down
28 changes: 22 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ mod native {

#[cfg(not(feature = "native"))]
mod wasm {
use std::cell::Cell;
use wasmer::{imports, Function, Instance, Memory, MemoryType, Module, Store, Value};

use super::{Barretenberg, Error, FeatureError};
Expand Down Expand Up @@ -279,11 +278,10 @@ mod wasm {

#[cfg(feature = "js")]
{
let view: js_sys::Uint8Array = memory.uint8view();
let view = memory.uint8view();
for (byte_id, cell_id) in (offset..(offset + arr.len())).enumerate() {
view.set_index(cell_id as u32, arr[byte_id])
}
return;
}

#[cfg(not(feature = "js"))]
Expand All @@ -309,12 +307,15 @@ mod wasm {
let end = start + length;

#[cfg(feature = "js")]
return memory.uint8view().to_vec()[start..end].to_vec();
return memory
.uint8view()
.subarray(start as u32, end as u32)
.to_vec();

#[cfg(not(feature = "js"))]
return memory.view()[start..end]
.iter()
.map(|cell: &Cell<u8>| cell.get())
.map(|cell| cell.get())
.collect();
}

Expand Down Expand Up @@ -430,14 +431,29 @@ mod wasm {
let mut ptr_end = 0;
let byte_view = env.memory.uint8view();

#[cfg(feature = "js")]
for (i, cell) in byte_view.to_vec()[ptr as usize..].iter().enumerate() {
if cell != &0_u8 {
ptr_end = i;
} else {
break;
}
}

#[cfg(not(feature = "js"))]
for (i, cell) in byte_view[ptr as usize..].iter().enumerate() {
if cell != &Cell::new(0) {
if cell.get() != 0 {
ptr_end = i;
} else {
break;
}
}

#[cfg(feature = "js")]
let str_vec: Vec<_> =
byte_view.to_vec()[ptr as usize..=(ptr + ptr_end as i32) as usize].to_vec();

#[cfg(not(feature = "js"))]
let str_vec: Vec<_> = byte_view[ptr as usize..=(ptr + ptr_end as i32) as usize]
.iter()
.cloned()
Expand Down

0 comments on commit 4a8099a

Please sign in to comment.