Skip to content

Commit

Permalink
Add_option_to_simulate_builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
YairVaknin-starkware committed Feb 17, 2025
1 parent 6182e1f commit 7fd34a9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Cairo-VM Changelog

#### Upcoming Changes
* feat: adding option to simulate builtins [#1956](https://github.com/lambdaclass/cairo-vm/pull/1956)

* feat: adding `all_cairo_stwo` layout to vm [#1957](https://github.com/lambdaclass/cairo-vm/pull/1957)

* feat: implement `Blake2s` opcode in VM [#1927](https://github.com/lambdaclass/cairo-vm/pull/1927)
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/runners/builtin_runner/ec_op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct EcOpBuiltinRunner {
}

impl EcOpBuiltinRunner {
pub(crate) fn new(ratio: Option<u32>, included: bool) -> Self {
pub fn new(ratio: Option<u32>, included: bool) -> Self {
EcOpBuiltinRunner {
base: 0,
ratio,
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/runners/builtin_runner/keccak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct KeccakBuiltinRunner {
}

impl KeccakBuiltinRunner {
pub(crate) fn new(ratio: Option<u32>, included: bool) -> Self {
pub fn new(ratio: Option<u32>, included: bool) -> Self {
KeccakBuiltinRunner {
base: 0,
ratio,
Expand Down
2 changes: 1 addition & 1 deletion vm/src/vm/runners/builtin_runner/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct SignatureBuiltinRunner {
}

impl SignatureBuiltinRunner {
pub(crate) fn new(ratio: Option<u32>, included: bool) -> Self {
pub fn new(ratio: Option<u32>, included: bool) -> Self {
SignatureBuiltinRunner {
base: 0,
included,
Expand Down
20 changes: 14 additions & 6 deletions vm/src/vm/vm_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ impl DeducedOperands {
pub struct VirtualMachine {
pub(crate) run_context: RunContext,
pub builtin_runners: Vec<BuiltinRunner>,
pub simulated_builtin_runners: Vec<BuiltinRunner>,
pub segments: MemorySegmentManager,
pub(crate) trace: Option<Vec<TraceEntry>>,
pub(crate) current_step: usize,
Expand Down Expand Up @@ -118,6 +119,7 @@ impl VirtualMachine {
VirtualMachine {
run_context,
builtin_runners: Vec::new(),
simulated_builtin_runners: Vec::new(),
trace,
current_step: 0,
skip_instruction_execution: false,
Expand Down Expand Up @@ -298,12 +300,17 @@ impl VirtualMachine {
&self,
address: Relocatable,
) -> Result<Option<MaybeRelocatable>, VirtualMachineError> {
for builtin in self.builtin_runners.iter() {
if builtin.base() as isize == address.segment_index {
match builtin.deduce_memory_cell(address, &self.segments.memory) {
Ok(maybe_reloc) => return Ok(maybe_reloc),
Err(error) => return Err(VirtualMachineError::RunnerError(error)),
};
let memory = &self.segments.memory;

for runner in self
.builtin_runners
.iter()
.chain(self.simulated_builtin_runners.iter())
{
if runner.base() as isize == address.segment_index {
return runner
.deduce_memory_cell(address, memory)
.map_err(VirtualMachineError::RunnerError);
}
}
Ok(None)
Expand Down Expand Up @@ -1312,6 +1319,7 @@ impl VirtualMachineBuilder {
VirtualMachine {
run_context: self.run_context,
builtin_runners: self.builtin_runners,
simulated_builtin_runners: Vec::new(),
trace: self.trace,
current_step: self.current_step,
skip_instruction_execution: self.skip_instruction_execution,
Expand Down

0 comments on commit 7fd34a9

Please sign in to comment.