acir/circuit/opcodes/
memory_operation.rs1use crate::native_types::{Expression, Witness};
2use acir_field::AcirField;
3use serde::{Deserialize, Serialize};
4
5#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, Hash, Copy, Default)]
7#[cfg_attr(feature = "arb", derive(proptest_derive::Arbitrary))]
8pub struct BlockId(pub u32);
9
10impl std::fmt::Display for BlockId {
11 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
12 write!(f, "b{}", self.0)
13 }
14}
15
16#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug, Hash)]
19#[cfg_attr(feature = "arb", derive(proptest_derive::Arbitrary))]
20pub struct MemOp<F> {
21 pub operation: Expression<F>,
23 pub index: Expression<F>,
25 pub value: Expression<F>,
28}
29
30impl<F: AcirField> MemOp<F> {
31 pub fn read_at_mem_index(index: Expression<F>, witness: Witness) -> Self {
34 MemOp { operation: Expression::zero(), index, value: witness.into() }
35 }
36
37 pub fn write_to_mem_index(index: Expression<F>, value: Expression<F>) -> Self {
39 MemOp { operation: Expression::one(), index, value }
40 }
41}