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

fix: add check against cache overflow #1285

Merged
merged 6 commits into from Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Expand Up @@ -2,13 +2,15 @@

#### Upcoming Changes

* fix(security): avoid OOM crashes when programs jump to very high invalid addresses.

* fix: add `to_bytes_be` to the felt when `lambdaworks-felt` feature is active [#1290](https://github.com/lambdaclass/cairo-vm/pull/1290)

* chore: mark `modpow` and `to_signed_bytes_le` as *deprecated* [#1290](https://github.com/lambdaclass/cairo-vm/pull/1290)

* fix: bump *lambdaworks-math* to latest version, that fixes no-std support [#1293](https://github.com/lambdaclass/cairo-vm/pull/1293)

* build: remove dependecy to `thiserror` (use `thiserror-no-std/std` instead)
* build: remove dependency to `thiserror` (use `thiserror-no-std/std` instead)

* chore: use LambdaWorks' implementation of bit operations for `Felt252` [#1291](https://github.com/lambdaclass/cairo-rs/pull/1291)

Expand Down
22 changes: 22 additions & 0 deletions cairo_programs/manually_compiled/overflowing_dict.json
@@ -0,0 +1,22 @@
{
"attributes": [],
"builtins": [],
"compiler_version": "0.11.0",
"data": [
"0x1104800180018000",
"0x80000000000001"
],
"hints": {},
"identifiers": {
"__main__.main": {
"decorators": [],
"pc": 0,
"type": "function"
}
},
"main_scope": "__main__",
"prime": "0x800000000000011000000000000000000000000000000000000000000000001",
"reference_manager": {
"references": []
}
}
7 changes: 7 additions & 0 deletions vm/src/tests/cairo_run_test.rs
Expand Up @@ -975,3 +975,10 @@ fn cairo_run_if_reloc_equal() {
let program_data = include_bytes!("../../../cairo_programs/if_reloc_equal.json");
run_program_simple_with_memory_holes(program_data, 4);
}

#[test]
fn cairo_run_overflowing_dict() {
let program_data =
include_bytes!("../../../cairo_programs/manually_compiled/overflowing_dict.json");
run_program_with_error(program_data, "Unknown memory cell at address");
}
4 changes: 4 additions & 0 deletions vm/src/vm/vm_core.rs
Expand Up @@ -462,6 +462,10 @@ impl VirtualMachine {
pub fn step_instruction(&mut self) -> Result<(), VirtualMachineError> {
let pc = self.run_context.pc.offset;

if self.segments.memory.data[0].len() <= pc {
return Err(MemoryError::UnknownMemoryCell(Box::new((0, pc).into())))?;
}

let mut inst_cache = core::mem::take(&mut self.instruction_cache);
inst_cache.resize((pc + 1).max(inst_cache.len()), None);

Expand Down