Skip to content

Commit d2bd6d0

Browse files
committed
Merge branch 'arbitrary-felts-sqrt-and-proptests' of github.com:lambdaclass/cairo-rs into arbitrary-felts-sqrt-and-proptests
2 parents ddfd395 + ab1ad00 commit d2bd6d0

File tree

19 files changed

+370
-47
lines changed

19 files changed

+370
-47
lines changed

.github/workflows/test_install.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
name: Test dependencies and cairo-rs install
22

33
on:
4+
merge_group:
45
push:
5-
branches-ignore: [ 'main' ]
6+
branches: [ main ]
7+
pull_request:
8+
branches: [ '*' ]
69

710
jobs:
811
install:

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* Implement `TryFrom<CasmContractClass> for Program`
4444
* Add `Cairo1HintProcessor`
4545

46-
* Add `CairoRunner::get_program method` [#1123](https://github.com/lambdaclass/cairo-rs/pull/1123):
46+
#### [0.4.0] - 2023-05-12
4747

4848
* perf: insert elements from the tail in `load_data` so reallocation happens only once [#1117](https://github.com/lambdaclass/cairo-rs/pull/1117)
4949

@@ -197,6 +197,10 @@
197197

198198
BREAKING: added a new error variant `MemoryError::VecCapacityExceeded`
199199

200+
* perf: specialize addition for `u64` and `Felt252` [#932](https://github.com/lambdaclass/cairo-rs/pull/932)
201+
* Avoids the creation of a new `Felt252` instance for additions with a very restricted valid range
202+
* This impacts specially the addition of `Relocatable` with `Felt252` values in `update_pc`, which take a significant amount of time in some benchmarks
203+
200204
* fix(starknet-crypto): bump version to `0.5.0` [#1088](https://github.com/lambdaclass/cairo-rs/pull/1088)
201205
* This includes the fix for a `panic!` in `ecdsa::verify`.
202206
See: [#365](https://github.com/xJonathanLEI/starknet-rs/issues/365) and [#366](https://github.com/xJonathanLEI/starknet-rs/pulls/366)

Cargo.lock

Lines changed: 12 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ members = [".", "cairo-vm-cli", "felt", "hint_accountant", "./deps/parse-hyperli
33

44
[package]
55
name = "cairo-vm"
6-
version = "0.3.0-rc1"
6+
version = "0.4.0"
77
edition = "2021"
88
license = "Apache-2.0"
99
description = "Blazing fast Cairo interpreter"
10+
repository = "https://github.com/lambdaclass/cairo-rs/"
1011

1112
[features]
1213
default = ["std", "with_mimalloc"]
@@ -73,10 +74,10 @@ thiserror-no-std = "2.0.2"
7374
# https://stackoverflow.com/questions/70630556/parse-allowing-nested-parentheses-in-nom
7475
# There is a proposal for extending nom::delimited to use this function:
7576
# https://github.com/Geal/nom/issues/1253
76-
parse-hyperlinks = { package = "cairo-take_until_unbalanced", path = "./deps/parse-hyperlinks", version = "0.24.2-rc1", default-features = false, features = [
77+
parse-hyperlinks = { package = "cairo-take_until_unbalanced", path = "./deps/parse-hyperlinks", version = "0.25.0", default-features = false, features = [
7778
"alloc",
7879
] }
79-
felt = { package = "cairo-felt", path = "./felt", version = "0.3.0-rc1", default-features = false, features = [
80+
felt = { package = "cairo-felt", path = "./felt", version = "0.4.0", default-features = false, features = [
8081
"alloc",
8182
] }
8283
bitvec = { version = "1", default-features = false, features = ["alloc"] }

RELEASE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Release Process
2+
3+
## Typical workflow
4+
25
- [ ] Pull latest from `main` branch.
36
`git checkout main && git pull origin main`
47
- [ ] Determine release version string dependending on whether changes included
@@ -35,3 +38,11 @@
3538
- If it is a release candidate, mark it as a draft release.
3639
- [ ] Announce release through corresponding channels.
3740

41+
## Hotfix releases
42+
43+
Sometimes there's a critical bug in a released version and we made breaking changes in `main` since. To push a non-breaking hotfix, you need the follow the original steps but basing using the release branch you created previously as base and bumping the patch level.
44+
45+
## Retroactive releases
46+
47+
In the case we want to push a new release from a revision other than `HEAD` (say, we introduced features that we'd rather not ship yet), there would be no base commit to compare to for the normal GitHub PR, as it can only merge branches. This means we lose the review instance before publishing.
48+
A solution is branching twice, once to diverge from main and one for making the needed changes and creating a PR against the original commit.

bench/criterion_benchmark.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use cairo_vm::{
2+
felt::Felt252,
23
types::program::Program,
34
vm::{runners::cairo_runner::CairoRunner, vm_core::VirtualMachine},
45
};
5-
use criterion::{black_box, criterion_group, criterion_main, BatchSize, Criterion};
6+
use criterion::{black_box, criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion};
7+
use num_traits::Zero;
68

79
#[cfg(feature = "with_mimalloc")]
810
use mimalloc::MiMalloc;
@@ -58,5 +60,39 @@ fn load_program_data(c: &mut Criterion) {
5860
});
5961
}
6062

63+
fn add_u64_with_felt252(c: &mut Criterion) {
64+
// There are 9 possible cases:
65+
// - The felt is `0`
66+
// - The felt is `-1` and the result in range
67+
// - The felt is `-1` but the result is out of range (the u64 is `0`)
68+
// - The felt is positive and the result in range
69+
// - The felt is positive and the result is out of range
70+
// - The felt is `> u64::MAX` which always causes to be out of range
71+
// - The felt is `<= -2` and the result is in range
72+
// - The felt is `<= -2` and the result is out of range
73+
// - The felt is `< -u64::MAX` which always causes to be out of range
74+
// I consider all of these cases because branching is the most likely
75+
// bottleneck here.
76+
let cases = [
77+
(1u64, Felt252::zero()),
78+
(1u64, Felt252::from(-1i128)),
79+
(0u64, Felt252::from(-1i128)),
80+
(0u64, Felt252::from(1i128)),
81+
(1u64, Felt252::from(u64::MAX as i128)),
82+
(0u64, Felt252::from(u64::MAX as i128 + 1i128)),
83+
(2u64, Felt252::from(-2i128)),
84+
(1u64, Felt252::from(-2i128)),
85+
(0u64, Felt252::from(-(u64::MAX as i128) - 1i128)),
86+
];
87+
let mut group = c.benchmark_group("add_u64_with_felt");
88+
for (i, case) in cases.iter().enumerate() {
89+
group.bench_with_input(BenchmarkId::from_parameter(i), case, |b, (lhs, rhs)| {
90+
b.iter(|| *lhs + rhs);
91+
});
92+
}
93+
group.finish();
94+
}
95+
96+
criterion_group!(felt, add_u64_with_felt252);
6197
criterion_group!(runner, build_many_runners, load_program_data, parse_program);
62-
criterion_main!(runner);
98+
criterion_main!(felt, runner);

cairo-vm-cli/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[package]
22
name = "cairo-vm-cli"
3-
version = "0.3.0-rc1"
3+
version = "0.4.0"
44
edition = "2021"
55

66
[dependencies]
77
bincode = { version = "2.0.0-rc.2", tag = "v2.0.0-rc.2", git = "https://github.com/bincode-org/bincode.git" }
8-
cairo-vm = { path = "..", version = "0.3.0-rc1" }
8+
cairo-vm = { path = "..", version = "0.4.0" }
99
clap = { version = "3.2.5", features = ["derive"] }
1010
mimalloc = { version = "0.1.29", default-features = false, optional = true }
1111
nom = "7"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[contract]
2+
mod Felt252Dict {
3+
4+
use dict::{felt252_dict_entry_finalize, Felt252DictTrait};
5+
/// An external method that requires the `segment_arena` builtin.
6+
#[external]
7+
fn squash_empty_dict() -> bool {
8+
let x = felt252_dict_new::<felt252>();
9+
x.squash();
10+
return true;
11+
}
12+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#[contract]
2+
mod FieldSqrt {
3+
use core::traits::Into;
4+
use option::OptionTrait;
5+
use ec::ec_point_from_x;
6+
use ec::ec_point_non_zero;
7+
use ec::ec_point_unwrap;
8+
9+
#[external]
10+
fn field_sqrt() -> felt252 {
11+
let p = ec_point_from_x(10).unwrap();
12+
let p_nz = ec_point_non_zero(p);
13+
14+
let (qx, _) = ec_point_unwrap(p_nz);
15+
16+
assert(qx == 10, 'bad finalize x');
17+
qx
18+
}
19+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#[contract]
2+
mod RandomEcPoint{
3+
use option::OptionTrait;
4+
use ec::ec_state_init;
5+
use ec::ec_state_add;
6+
use ec::ec_state_try_finalize_nz;
7+
use ec::ec_point_from_x;
8+
use ec::ec_point_non_zero;
9+
use ec::ec_point_unwrap;
10+
11+
// Test taken from https://github.com/starkware-libs/cairo/blob/a0ead7c0b8e297d281c7213151cd43ac11de5042/corelib/src/test/ec_test.cairo#L17
12+
#[external]
13+
fn random_ec_point() -> felt252{
14+
let p = ec_point_from_x(1).unwrap();
15+
let p_nz = ec_point_non_zero(p);
16+
17+
let mut state = ec_state_init();
18+
ec_state_add(ref state, p_nz);
19+
20+
let q = ec_state_try_finalize_nz(state).expect('zero point');
21+
let (qx, qy) = ec_point_unwrap(q);
22+
23+
assert(qx == 1, 'bad finalize x');
24+
qx
25+
}
26+
27+
}

0 commit comments

Comments
 (0)