Skip to content

Commit

Permalink
Add a test that runs a cairo 0 contract from a cairo program (#1494)
Browse files Browse the repository at this point in the history
* Usa a Hashmap for HintRanges

* Add execute_and_mutate_hints

* comments

* Fix hashmap ranges-related stuff

* Add execute_hint_extensive

* Process

* Add error handling

* Add comments & remove previous impl

* Use Box to reduce output size

* Fix tests

* Fix tests

* Fix bug

* Revert hook changes + fmt

* Uncomment code

* revert hook-related vchanges'

'
'

* Add comments

* Remove old comments from proxy era

* Revert "Use Box to reduce output size"

This reverts commit fc76a36.

* Add back RelocataedTrace struct

* Move relocated trace back to runner

* Remove trace relocation from vm

* Fix test

* Update tests

* clippy

* clippy

* Remove dbg print + add changelog entry

* Add test check

* Add test check

* Simplify output type of execute_hint_extensive`
`

* Add missing wasm import

* Only use instruction cache when running from program segment

* Add test

* Update test

* Add unit tests

* Fmt

* Add changelog entry

* Fix pr num

* Fix tests after merge

* Initial progress

* Complete skeleton

* Add bytecode

* Add hints

* Use a simpler hint for test

* fmt

* Add trace check

* Add comment explaining file purpose

* Simplify code comments

* Simplify code comments

* Make relocate_trace public

* List breaking changes

* List pr purpose in changelog

* Add disclaimers for execute_hint & execute_hint_extensive

* Start changelog

* List functionality changes in changelog

* fix names

* Add no-std import

* no-std

* no-std

---------

Co-authored-by: Pedro Fontana <[email protected]>
  • Loading branch information
fmoletta and pefontana authored Nov 29, 2023
1 parent 8daae06 commit b657576
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 7 deletions.
13 changes: 6 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

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

* BREAKING: 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 & `relocate_trace` method to `CairoRunner`.
* Swap `TraceEntry` for `RelocatedTraceEntry` type in `write_encoded_trace` & `PublicInput::new` signatures.
* Now takes into account the program counter's segment index when building the execution trace instead of assuming it to be 0.
* feat: Add HintProcessor::execute_hint_extensive + refactor hint_ranges [#1491](https://github.com/lambdaclass/cairo-vm/pull/1491)

* Add trait method `HintProcessorLogic::execute_hint_extensive`:
Expand All @@ -14,13 +20,6 @@
* `pub fn step_hint(&mut self, hint_executor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &mut Vec<Box<dyn Any>>, constants: &HashMap<String, Felt252>) -> Result<(), VirtualMachineError>` -> `pub fn step_hint(&mut self, hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &mut Vec<Box<dyn Any>>, hint_ranges: &mut HashMap<Relocatable, HintRange>, constants: &HashMap<String, Felt252>) -> Result<(), VirtualMachineError>`
* `pub fn step(&mut self, hint_executor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_data: &[Box<dyn Any>], constants: &HashMap<String, Felt252>) -> Result<(), VirtualMachineError>` -> `pub fn step(&mut self, hint_processor: &mut dyn HintProcessor, exec_scopes: &mut ExecutionScopes, hint_datas: &mut Vec<Box<dyn Any>>, hint_ranges: &mut HashMap<Relocatable, HintRange>, constants: &HashMap<String, Felt252>) -> Result<(), VirtualMachineError>`

* BREAKING: 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 & `relocate_trace` method to `CairoRunner`.
* Swap `TraceEntry` for `RelocatedTraceEntry` type in `write_encoded_trace` & `PublicInput::new` signatures.
* Now takes into account the program counter's segment index when building the execution trace instead of assuming it to be 0.

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

* feat: add `cairo_run_program` function that takes a `Program` as an arg. [#1496](https://github.com/lambdaclass/cairo-vm/pull/1496)
Expand Down
32 changes: 32 additions & 0 deletions cairo_programs/noretrocompat/starknet_os_deprecated_cc.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from starkware.starknet.core.os.contract_class.deprecated_compiled_class import (
DeprecatedCompiledClass,
DeprecatedCompiledClassFact
)
from starkware.cairo.common.alloc import alloc

func main() {
alloc_locals;
local compiled_class_facts: DeprecatedCompiledClassFact*;
%{ ids.compiled_class_facts = segments.add() %}
let compiled_class_fact = compiled_class_facts;
let compiled_class = compiled_class_fact.compiled_class;
%{
from starkware.starknet.services.api.contract_class.contract_class import DeprecatedCompiledClass
from starkware.starknet.core.os.contract_class.deprecated_class_hash import (
get_deprecated_contract_class_struct,
)
with open("test_contract.json", "r") as f:
compiled_class = DeprecatedCompiledClass.loads(f.read())
cairo_contract = get_deprecated_contract_class_struct(
identifiers=ids._context.identifiers, contract_class=compiled_class)
ids.compiled_class = segments.gen_arg(cairo_contract)
%}
local compiled_class: DeprecatedCompiledClass* = compiled_class;
local destination: felt* = compiled_class.bytecode_ptr;
%{
vm_load_program(compiled_class.program, ids.compiled_class.bytecode_ptr)
%}
call abs destination;
return ();
}
2 changes: 2 additions & 0 deletions vm/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use wasm_bindgen_test::*;
use alloc::{string::String, vec::Vec};

mod bitwise_test;
#[cfg(test)]
mod run_deprecated_contract_class_simplified;

#[cfg(feature = "cairo-1-hints")]
mod cairo_1_run_from_entrypoint_tests;
Expand Down
Loading

0 comments on commit b657576

Please sign in to comment.