diff --git a/acvm-repo/acvm/src/pwg/memory_op.rs b/acvm-repo/acvm/src/pwg/memory_op.rs index 1a6519d19c5..2a83bf2531c 100644 --- a/acvm-repo/acvm/src/pwg/memory_op.rs +++ b/acvm-repo/acvm/src/pwg/memory_op.rs @@ -21,6 +21,19 @@ pub(crate) struct MemoryOpSolver { } impl MemoryOpSolver { + fn index_from_field(&self, index: F) -> Result> { + if index.num_bits() <= 32 { + let memory_index = index.try_to_u64().unwrap() as MemoryIndex; + Ok(memory_index) + } else { + Err(OpcodeResolutionError::IndexOutOfBounds { + opcode_location: ErrorLocation::Unresolved, + index, + array_size: self.block_len, + }) + } + } + fn write_memory_index( &mut self, index: MemoryIndex, @@ -29,7 +42,7 @@ impl MemoryOpSolver { if index >= self.block_len { return Err(OpcodeResolutionError::IndexOutOfBounds { opcode_location: ErrorLocation::Unresolved, - index, + index: F::from(index as u128), array_size: self.block_len, }); } @@ -40,7 +53,7 @@ impl MemoryOpSolver { fn read_memory_index(&self, index: MemoryIndex) -> Result> { self.block_value.get(&index).copied().ok_or(OpcodeResolutionError::IndexOutOfBounds { opcode_location: ErrorLocation::Unresolved, - index, + index: F::from(index as u128), array_size: self.block_len, }) } @@ -72,7 +85,7 @@ impl MemoryOpSolver { // Find the memory index associated with this memory operation. let index = get_value(&op.index, initial_witness)?; - let memory_index = index.try_to_u64().unwrap() as MemoryIndex; + let memory_index = self.index_from_field(index)?; // Calculate the value associated with this memory operation. // @@ -193,9 +206,9 @@ mod tests { err, Some(crate::pwg::OpcodeResolutionError::IndexOutOfBounds { opcode_location: _, - index: 2, + index, array_size: 2 - }) + }) if index == FieldElement::from(2u128) )); } diff --git a/acvm-repo/acvm/src/pwg/mod.rs b/acvm-repo/acvm/src/pwg/mod.rs index ddc708e4238..fa485e98f5e 100644 --- a/acvm-repo/acvm/src/pwg/mod.rs +++ b/acvm-repo/acvm/src/pwg/mod.rs @@ -127,7 +127,7 @@ pub enum OpcodeResolutionError { payload: Option>, }, #[error("Index out of bounds, array has size {array_size:?}, but index was {index:?}")] - IndexOutOfBounds { opcode_location: ErrorLocation, index: u32, array_size: u32 }, + IndexOutOfBounds { opcode_location: ErrorLocation, index: F, array_size: u32 }, #[error("Cannot solve opcode: {invalid_input_bit_size}")] InvalidInputBitSize { opcode_location: ErrorLocation, diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index d20e037ff8c..672643d430b 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -234,7 +234,8 @@ fn needs_lock(cmd: &NargoCommand) -> Option { | NargoCommand::Compile(..) | NargoCommand::Execute(..) | NargoCommand::Export(..) - | NargoCommand::Info(..) => Some(true), + | NargoCommand::Info(..) + | NargoCommand::Fuzz(..) => Some(true), NargoCommand::Debug(..) | NargoCommand::Test(..) => Some(false), NargoCommand::Fmt(..) | NargoCommand::New(..)