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

Commit

Permalink
feat: add support for atomic memory opcodes (#232)
Browse files Browse the repository at this point in the history
* Add support for atomic memory opcodes

* switch to acvm 0.20.0

* update cargo.lock
  • Loading branch information
guipublic committed Jul 21, 2023
1 parent b15050a commit a7aa6e9
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
30 changes: 16 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
crate-type = ["cdylib", "lib"]

[dependencies]
acvm = { version = "0.19.0", features = ["bn254"] }
acvm = { version = "0.20.0", features = ["bn254"] }
bincode = "1.3.3"
bytesize = "1.2"
reqwest = { version = "0.11.16", default-features = false, features = [
Expand Down
2 changes: 2 additions & 0 deletions src/acvm_interop/proof_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ impl ProofSystemCompiler for Barretenberg {
Opcode::ROM(_) => true,
Opcode::RAM(_) => true,
Opcode::Brillig(_) => true,
Opcode::MemoryInit { .. } => true,
Opcode::MemoryOp { .. } => true,
Opcode::BlackBoxFuncCall(func) => match func.get_black_box_func() {
BlackBoxFunc::AND
| BlackBoxFunc::XOR
Expand Down
33 changes: 33 additions & 0 deletions src/barretenberg_structures.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::BTreeMap;

use acvm::acir::circuit::opcodes::{BlackBoxFuncCall, FunctionInput, MemoryBlock};
use acvm::acir::circuit::{Circuit, Opcode};
use acvm::acir::native_types::Expression;
Expand Down Expand Up @@ -841,6 +843,7 @@ impl TryFrom<&Circuit> for ConstraintSystem {
let mut hash_to_field_constraints: Vec<HashToFieldConstraint> = Vec::new();
let mut recursion_constraints: Vec<RecursionConstraint> = Vec::new();

let mut blocks: BTreeMap<u32, BlockConstraint> = BTreeMap::new();
for gate in circuit.opcodes.iter() {
match gate {
Opcode::Arithmetic(expression) => {
Expand Down Expand Up @@ -1345,6 +1348,36 @@ impl TryFrom<&Circuit> for ConstraintSystem {
Opcode::ROM(block) => {
block_constraints.push(BlockConstraint::from_memory_block(block, false))
}
Opcode::MemoryOp { block_id, op } => {
let block = blocks
.get_mut(&block_id.0)
.expect("memory operation on an uninitialized block");

let index = serialize_arithmetic_gates(&op.index);
let value = serialize_arithmetic_gates(&op.value);
let bb_op = MemOpBarretenberg {
is_store: op.operation.to_const().unwrap().to_u128() as i8,
index,
value,
};
block.trace.push(bb_op);
}
Opcode::MemoryInit { block_id, init } => {
let init = init
.iter()
.map(|w| {
let mut constraint = Constraint::default();
constraint.set_linear_term(FieldElement::one(), w.as_usize() as i32);
constraint
})
.collect();
let block = BlockConstraint {
init,
trace: Vec::new(),
is_ram: 1,
};
blocks.insert(block_id.0, block);
}
}
}

Expand Down

0 comments on commit a7aa6e9

Please sign in to comment.