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

Commit a7aa6e9

Browse files
authored
feat: add support for atomic memory opcodes (#232)
* Add support for atomic memory opcodes * switch to acvm 0.20.0 * update cargo.lock
1 parent b15050a commit a7aa6e9

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

Cargo.lock

Lines changed: 16 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ license = "MIT OR Apache-2.0"
1313
crate-type = ["cdylib", "lib"]
1414

1515
[dependencies]
16-
acvm = { version = "0.19.0", features = ["bn254"] }
16+
acvm = { version = "0.20.0", features = ["bn254"] }
1717
bincode = "1.3.3"
1818
bytesize = "1.2"
1919
reqwest = { version = "0.11.16", default-features = false, features = [

src/acvm_interop/proof_system.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ impl ProofSystemCompiler for Barretenberg {
2727
Opcode::ROM(_) => true,
2828
Opcode::RAM(_) => true,
2929
Opcode::Brillig(_) => true,
30+
Opcode::MemoryInit { .. } => true,
31+
Opcode::MemoryOp { .. } => true,
3032
Opcode::BlackBoxFuncCall(func) => match func.get_black_box_func() {
3133
BlackBoxFunc::AND
3234
| BlackBoxFunc::XOR

src/barretenberg_structures.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::collections::BTreeMap;
2+
13
use acvm::acir::circuit::opcodes::{BlackBoxFuncCall, FunctionInput, MemoryBlock};
24
use acvm::acir::circuit::{Circuit, Opcode};
35
use acvm::acir::native_types::Expression;
@@ -841,6 +843,7 @@ impl TryFrom<&Circuit> for ConstraintSystem {
841843
let mut hash_to_field_constraints: Vec<HashToFieldConstraint> = Vec::new();
842844
let mut recursion_constraints: Vec<RecursionConstraint> = Vec::new();
843845

846+
let mut blocks: BTreeMap<u32, BlockConstraint> = BTreeMap::new();
844847
for gate in circuit.opcodes.iter() {
845848
match gate {
846849
Opcode::Arithmetic(expression) => {
@@ -1345,6 +1348,36 @@ impl TryFrom<&Circuit> for ConstraintSystem {
13451348
Opcode::ROM(block) => {
13461349
block_constraints.push(BlockConstraint::from_memory_block(block, false))
13471350
}
1351+
Opcode::MemoryOp { block_id, op } => {
1352+
let block = blocks
1353+
.get_mut(&block_id.0)
1354+
.expect("memory operation on an uninitialized block");
1355+
1356+
let index = serialize_arithmetic_gates(&op.index);
1357+
let value = serialize_arithmetic_gates(&op.value);
1358+
let bb_op = MemOpBarretenberg {
1359+
is_store: op.operation.to_const().unwrap().to_u128() as i8,
1360+
index,
1361+
value,
1362+
};
1363+
block.trace.push(bb_op);
1364+
}
1365+
Opcode::MemoryInit { block_id, init } => {
1366+
let init = init
1367+
.iter()
1368+
.map(|w| {
1369+
let mut constraint = Constraint::default();
1370+
constraint.set_linear_term(FieldElement::one(), w.as_usize() as i32);
1371+
constraint
1372+
})
1373+
.collect();
1374+
let block = BlockConstraint {
1375+
init,
1376+
trace: Vec::new(),
1377+
is_ram: 1,
1378+
};
1379+
blocks.insert(block_id.0, block);
1380+
}
13481381
}
13491382
}
13501383

0 commit comments

Comments
 (0)