Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow running instructions from pcs outside the program segment #1493

Merged
merged 30 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b0073a1
Add back RelocataedTrace struct
fmoletta Nov 23, 2023
f85e52c
Move relocated trace back to runner
fmoletta Nov 23, 2023
9f093ac
Remove trace relocation from vm
fmoletta Nov 23, 2023
ab9eb1a
Fix test
fmoletta Nov 23, 2023
f61c82c
Update tests
fmoletta Nov 23, 2023
c47c41c
clippy
fmoletta Nov 23, 2023
def1bbe
clippy
fmoletta Nov 23, 2023
94393f1
Remove dbg print + add changelog entry
fmoletta Nov 23, 2023
f3436d5
Add test check
fmoletta Nov 23, 2023
1a81ed1
Add test check
fmoletta Nov 23, 2023
54c4ac2
Add missing wasm import
fmoletta Nov 23, 2023
c024166
Merge branch 'main' of github.com:lambdaclass/cairo-vm into revert-tr…
fmoletta Nov 23, 2023
83335e6
Only use instruction cache when running from program segment
fmoletta Nov 24, 2023
dd7994d
Add test
fmoletta Nov 24, 2023
ef9f9e5
Merge branch 'revert-trace-optimization' into run-instruction-from-ot…
fmoletta Nov 24, 2023
df19f11
Update test
fmoletta Nov 24, 2023
8a527c5
Add unit tests
fmoletta Nov 24, 2023
90720ee
Fmt
fmoletta Nov 24, 2023
add9934
Add changelog entry
fmoletta Nov 24, 2023
200dd7a
Fix pr num
fmoletta Nov 24, 2023
da24777
Merge branch 'revert-trace-optimization' into run-instruction-from-ot…
fmoletta Nov 24, 2023
aad4dc9
Make relocate_trace public
fmoletta Nov 24, 2023
5c517d8
List breaking changes
fmoletta Nov 24, 2023
8ca276f
List pr purpose in changelog
fmoletta Nov 24, 2023
4ff9c3a
Merge branch 'revert-trace-optimization' into run-instruction-from-ot…
fmoletta Nov 24, 2023
97b98ba
Merge branch 'main' into run-instruction-from-other-pc
fmoletta Nov 27, 2023
a71142f
Merge branch 'main' into run-instruction-from-other-pc
fmoletta Nov 27, 2023
cea1104
Merge branch 'run-instruction-from-other-pc' of github.com:lambdaclas…
fmoletta Nov 28, 2023
b175a3c
Fix tests
fmoletta Nov 28, 2023
2a3a0fb
Merge branch 'main' into run-instruction-from-other-pc
pefontana Nov 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@

#### Upcoming Changes

* feat: Allow running instructions from pcs outside the program segement [#1493](https://github.com/lambdaclass/cairo-vm/pull/14923)

* feat: Partially Revert `Optimize trace relocation #906` [#1492](https://github.com/lambdaclass/cairo-vm/pull/1492)

* Remove methods `VirtualMachine::get_relocated_trace`& `VirtualMachine::relocate_trace`
* Add `relocated_trace` field to `CairoRunner`

* feat: add debugging capabilities behind `print` feature flag. [#1476](https://github.com/lambdaclass/cairo-vm/pull/1476)

#### [0.9.1] - 2023-11-16


* chore: bump `cairo-lang-` dependencies to 2.3.1 [#1482](https://github.com/lambdaclass/cairo-vm/pull/1482), [#1483](https://github.com/lambdaclass/cairo-vm/pull/1483)

* feat: Make PublicInput fields public [#1474](https://github.com/lambdaclass/cairo-vm/pull/1474)
Expand Down
5 changes: 4 additions & 1 deletion cairo-vm-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ fn run(args: impl Iterator<Item = String>) -> Result<(), Error> {
}

if let Some(trace_path) = args.trace_file {
let relocated_trace = vm.get_relocated_trace()?;
let relocated_trace = cairo_runner
.relocated_trace
.as_ref()
.ok_or(Error::Trace(TraceError::TraceNotRelocated))?;

let trace_file = std::fs::File::create(trace_path)?;
let mut trace_writer =
Expand Down
6 changes: 4 additions & 2 deletions cairo1-run/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,14 @@ fn run(args: impl Iterator<Item = String>) -> Result<Vec<MaybeRelocatable>, Erro
runner.relocate(&mut vm, true)?;

if let Some(trace_path) = args.trace_file {
let relocated_trace = vm.get_relocated_trace()?;
let relocated_trace = runner
.relocated_trace
.ok_or(Error::Trace(TraceError::TraceNotRelocated))?;
let trace_file = std::fs::File::create(trace_path)?;
let mut trace_writer =
FileWriter::new(io::BufWriter::with_capacity(3 * 1024 * 1024, trace_file));

cairo_run::write_encoded_trace(relocated_trace, &mut trace_writer)?;
cairo_run::write_encoded_trace(&relocated_trace, &mut trace_writer)?;
trace_writer.flush()?;
}
if let Some(memory_path) = args.memory_file {
Expand Down
24 changes: 8 additions & 16 deletions fuzzer/Cargo.lock

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

4 changes: 2 additions & 2 deletions vm/src/air_public_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
types::layout::CairoLayout,
vm::{
errors::{trace_errors::TraceError, vm_errors::VirtualMachineError},
trace::trace_entry::TraceEntry,
trace::trace_entry::RelocatedTraceEntry,
},
};

Expand Down Expand Up @@ -73,7 +73,7 @@ impl<'a> PublicInput<'a> {
dyn_layout_params: Option<&'a CairoLayout>,
public_memory_addresses: &[(usize, usize)],
memory_segment_addresses: HashMap<&'static str, (usize, usize)>,
trace: &[TraceEntry],
trace: &[RelocatedTraceEntry],
rc_limits: (isize, isize),
) -> Result<Self, PublicInputError> {
let memory_entry =
Expand Down
8 changes: 4 additions & 4 deletions vm/src/cairo_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub struct EncodeTraceError(usize, bincode::error::EncodeError);
/// Bincode encodes to little endian by default and each trace entry is composed of
/// 3 usize values that are padded to always reach 64 bit size.
pub fn write_encoded_trace(
relocated_trace: &[crate::vm::trace::trace_entry::TraceEntry],
relocated_trace: &[crate::vm::trace::trace_entry::RelocatedTraceEntry],
dest: &mut impl Writer,
) -> Result<(), EncodeTraceError> {
for (i, entry) in relocated_trace.iter().enumerate() {
Expand Down Expand Up @@ -318,11 +318,11 @@ mod tests {
// relocate memory so we can dump it to file
assert!(cairo_runner.relocate(&mut vm, false).is_ok());

let trace_entries = vm.get_relocated_trace().unwrap();
let trace_entries = cairo_runner.relocated_trace.unwrap();
let mut buffer = [0; 24];
let mut buff_writer = SliceWriter::new(&mut buffer);
// write cairo_rs vm trace file
write_encoded_trace(trace_entries, &mut buff_writer).unwrap();
write_encoded_trace(&trace_entries, &mut buff_writer).unwrap();

// compare that the original cairo vm trace file and cairo_rs vm trace files are equal
assert_eq!(buffer, *expected_encoded_trace);
Expand Down Expand Up @@ -369,6 +369,6 @@ mod tests {
.run_until_pc(end, &mut vm, &mut hint_processor)
.is_ok());
assert!(cairo_runner.relocate(&mut vm, false).is_ok());
assert!(vm.get_relocated_trace().is_err());
assert!(cairo_runner.relocated_trace.is_none());
}
}
6 changes: 3 additions & 3 deletions vm/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::vm::errors::cairo_run_errors::CairoRunError;
#[cfg(feature = "cairo-1-hints")]
use crate::vm::runners::cairo_runner::RunResources;
use crate::vm::trace::trace_entry::RelocatedTraceEntry;
#[cfg(feature = "cairo-1-hints")]
use crate::{
hint_processor::cairo_1_hint_processor::hint_processor::Cairo1HintProcessor,
Expand All @@ -22,7 +23,6 @@ use crate::stdlib::prelude::*;
use crate::{
cairo_run::{cairo_run, CairoRunConfig},
hint_processor::builtin_hint_processor::builtin_hint_processor_definition::BuiltinHintProcessor,
vm::trace::trace_entry::TraceEntry,
};

#[cfg(target_arch = "wasm32")]
Expand Down Expand Up @@ -93,9 +93,9 @@ pub(self) fn run_program(
let expected_trace: Vec<_> = trace
.iter()
.copied()
.map(|(pc, ap, fp)| TraceEntry { pc, ap, fp })
.map(|(pc, ap, fp)| RelocatedTraceEntry { pc, ap, fp })
.collect();
let trace = vm.get_relocated_trace().unwrap();
let trace = runner.relocated_trace.as_ref().unwrap();
assert_eq!(trace.len(), expected_trace.len());
for (entry, expected) in trace.iter().zip(expected_trace.iter()) {
assert_eq!(entry, expected);
Expand Down
20 changes: 15 additions & 5 deletions vm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ pub mod test_utils {
pub(crate) use non_continuous_ids_data;

#[track_caller]
pub(crate) fn trace_check(actual: &[TraceEntry], expected: &[(usize, usize, usize)]) {
pub(crate) fn trace_check(
actual: &[TraceEntry],
expected: &[(crate::utils::Relocatable, usize, usize)],
) {
assert_eq!(actual.len(), expected.len());
for (entry, expected) in actual.iter().zip(expected.iter()) {
assert_eq!(&(entry.pc, entry.ap, entry.fp), expected);
Expand Down Expand Up @@ -704,22 +707,29 @@ mod test {
fn assert_trace() {
let trace = vec![
TraceEntry {
pc: 2,
pc: (0, 2).into(),
ap: 7,
fp: 1,
},
TraceEntry {
pc: 5,
pc: (0, 5).into(),
ap: 1,
fp: 0,
},
TraceEntry {
pc: 9,
pc: (0, 9).into(),
ap: 5,
fp: 7,
},
];
trace_check(&trace, &[(2, 7, 1), (5, 1, 0), (9, 5, 7)]);
trace_check(
&trace,
&[
((0, 2).into(), 7, 1),
((0, 5).into(), 1, 0),
((0, 9).into(), 5, 7),
],
);
}

#[test]
Expand Down
Loading
Loading