Skip to content

Commit

Permalink
Add EXCESS_BALANCE hint (#1777)
Browse files Browse the repository at this point in the history
* WIP

* Add MarginParams

* Impl imf

* Start excess_balance fn

* Add TODO comment

* refactor + handle errors

* Remove unused error

* Finish implementing hint

* Handle error

* Fix var names

* Setup hint test

* Fix test

* Fix test

* Fix test

* Fix test values

* Fix

* Update

* Fix

* Use constants

* Remove unwrap

* Remove allow

* Remove unused feature

* Add failure test case

* Fix test values

* Add no-std imports

* Add no-std imports

* Add hint code

* Add changelog entry

* Use checked arithmetic operations
  • Loading branch information
fmoletta committed Jun 6, 2024
1 parent 8ab4471 commit dfe3a5a
Show file tree
Hide file tree
Showing 9 changed files with 1,274 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#### Upcoming Changes

* feat: Add `EXCESS_BALANCE` hint [#1777](https://github.com/lambdaclass/cairo-vm/pull/1777)

#### [0.9.2] - 2024-01-3

* Change ec_op_impl() to use ProjectivePoint [#1534](https://github.com/lambdaclass/cairo-vm/pull/1534)
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ keccak = { workspace = true }
hashbrown = { workspace = true }
anyhow = { workspace = true }
thiserror-no-std = { workspace = true }
rust_decimal = { version = "1.35.0", default-features = false }

# only for std
num-prime = { version = "0.4.3", features = ["big-int"], optional = true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::{
ec_recover_divmod_n_packed, ec_recover_product_div_m, ec_recover_product_mod,
ec_recover_sub_a_b,
},
excess_balance::excess_balance_hint,
field_arithmetic::{u256_get_square_root, u384_get_square_root, uint384_div},
secp::{
ec_utils::{
Expand Down Expand Up @@ -815,6 +816,13 @@ impl HintProcessorLogic for BuiltinHintProcessor {
hint_code::SPLIT_XX => split_xx(vm, &hint_data.ids_data, &hint_data.ap_tracking),
#[cfg(feature = "skip_next_instruction_hint")]
hint_code::SKIP_NEXT_INSTRUCTION => skip_next_instruction(vm),
hint_code::EXCESS_BALANCE => excess_balance_hint(
vm,
&hint_data.ids_data,
&hint_data.ap_tracking,
constants,
exec_scopes,
),
code => Err(HintError::UnknownHint(code.to_string().into_boxed_str())),
}
}
Expand Down
11 changes: 11 additions & 0 deletions vm/src/hint_processor/builtin_hint_processor/dict_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,17 @@ impl DictTracker {
}
}

//Returns a reference to the contained dictionary, losing the dictionary type in the process
pub fn get_dictionary_ref(&self) -> &HashMap<MaybeRelocatable, MaybeRelocatable> {
match &self.data {
Dictionary::SimpleDictionary(dict) => dict,
Dictionary::DefaultDictionary {
dict,
default_value: _,
} => dict,
}
}

pub fn get_value(&mut self, key: &MaybeRelocatable) -> Result<&MaybeRelocatable, HintError> {
self.data
.get(key)
Expand Down
Loading

0 comments on commit dfe3a5a

Please sign in to comment.