Skip to content

Commit

Permalink
Add EXCESS_BALANCE hint & Bump Rust to 1.74 (base 0.9.x) (#1786)
Browse files Browse the repository at this point in the history
* Add `EXCESS_BALANCE` hint (#1777)

* 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

* lock flamegraph dep

* Lock more dependencies

* fix

* Lock more dependencies

* Update Rust version to 1.74.1 (#1605)

* Update rust version to 1.74.1

* cargo fmt -all

* Update Makefile

* cargo clippy --fix

* fix cargo clippy

* restore fuzzer/Cargo.lock

---------

Co-authored-by: Pedro Fontana <[email protected]>

* Apply clippy

* fmt

* Remove cairo1-run

* Revert "Remove cairo1-run"

This reverts commit ef5d214.

* Remove changes to cairo1-run crate

---------

Co-authored-by: Pedro Fontana <[email protected]>
Co-authored-by: Pedro Fontana <[email protected]>
  • Loading branch information
3 people authored Jun 7, 2024
1 parent 8ab4471 commit 3d00941
Show file tree
Hide file tree
Showing 27 changed files with 1,307 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
with:
components: rustfmt, clippy
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cairo_1_programs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
- name: Set up Cargo cache
uses: Swatinem/rust-cache@v2
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fresh_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
uses: actions/checkout@v3

- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1

- name: Install Pyenv
uses: "gabrielfalcao/pyenv-action@v13"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hint_accountant.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
- name: Set up Cargo cache
uses: Swatinem/rust-cache@v2
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hyperfine.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ jobs:

- name: Install Rust
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1

- name: Checkout
if: ${{ steps.cache.outputs.cache-hit != 'true' }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/iai_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
- name: Python3 Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/iai_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- name: Install Rust
if: ${{ steps.cache-iai-results.outputs.cache-hit != 'true' }}
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
- name: Set up cargo cache
if: ${{ steps.cache-iai-results.outputs.cache-hit != 'true' }}
uses: Swatinem/rust-cache@v2
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3
- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
- name: Python3 Build
Expand Down
10 changes: 1 addition & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v2
- name: Install stable toolchain
uses: dtolnay/[email protected]
- name: Publish crate cairo-felt
env:
CRATES_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: cargo publish --token ${CRATES_TOKEN} --all-features --manifest-path ./felt/Cargo.toml
# FIXME: there should be a better way to make sure the index in crates.io is updated before publishing
# cairo-vm but right now the step throws timeout and fails.
- name: wait for index in crates.io
run: sleep 300
uses: dtolnay/[email protected]
- name: Publish crate cairo-vm
env:
CRATES_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
with:
components: rustfmt, clippy
- name: Set up cargo cache
Expand Down Expand Up @@ -159,7 +159,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
with:
targets: wasm32-unknown-unknown

Expand Down Expand Up @@ -220,7 +220,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
with:
components: llvm-tools-preview
- name: Set up cargo cache
Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
runs-on: ubuntu-22.04
steps:
- name: Install Rust
uses: dtolnay/rust-toolchain@1.70.0
uses: dtolnay/rust-toolchain@1.74.1
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
- name: Checkout
Expand Down
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.

8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ build-cairo-2-compiler:
cargo-deps:
cargo install --version 0.3.1 iai-callgrind-runner
cargo install --version 1.1.0 cargo-criterion
cargo install --version 0.6.1 flamegraph
cargo install --version 0.6.1 flamegraph --locked
cargo install --version 1.14.0 hyperfine
cargo install --version 0.9.49 cargo-nextest
cargo install --version 0.5.9 cargo-llvm-cov
cargo install --version 0.12.1 wasm-pack
cargo install --version 0.9.49 cargo-nextest --locked
cargo install --version 0.5.9 cargo-llvm-cov --locked
cargo install --version 0.12.1 wasm-pack --locked

cairo1-run-deps:
cd cairo1-run; make deps
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ It's Turing-complete and it was created by [Starkware](https://starkware.co/) as

These are needed in order to compile and use the project.

- [Rust 1.70.0 or newer](https://www.rust-lang.org/tools/install)
- [Rust 1.74.1 or newer](https://www.rust-lang.org/tools/install)
- Cargo

#### Optional
Expand Down
2 changes: 1 addition & 1 deletion felt/src/lib_bigint_felt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ impl Add<&Felt252> for u64 {
};
// A single digit means this is effectively the sum of two `u64` numbers.
let Some(h0) = rhs_digits.next() else {
return self.checked_add(low)
return self.checked_add(low);
};
// Now we need to compare the 3 most significant digits.
// There are two relevant cases from now on, either `rhs` behaves like a
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.70.0"
channel = "1.74.1"
components = ["rustfmt", "clippy"]
profile = "minimal"
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 3d00941

Please sign in to comment.