Skip to content

Commit 0a05bba

Browse files
[Sierra-Emu] Fix felt-dict's overflow, circuits libfuncs and implement missing EcPoint libfunc (#1208)
* change initial gas due to overflows * fix some libfuncs in circuits * fix is() for circuits * remove Value::Unit from return values in get_output * match U96LimbsLessThanGuarantee correctly * some corrections to circuits * some corrections to circuits * fix failure_guarantee_verify to avoid panicking * fix circuits * more fixes to circuits + implement ec_zero libfunc * clippy * remove unnecesary tests * remove unnecesary file * fix branch index * add comment * fix eval_u96_limbs_less_than_guarantee_verify * remove circuit failure test * update trace dump with new Value::CircitOutputs * fmt * reviews + fix modulus in trace dump * remove unnecesary file * fix clippy * implement circuit_single_limb_less_than_guarantee_verify * fix trace dump for circuit outputs * fix felt_dict_get * fix felt_dict_get * implement U96LimbsLessThanGuarantee for trace dump * remove unnecessary code * fmt * fix felt_dict_entry_get * revert change in circuits.rs * remove unwanted file * revert unwanted change * revert unwanted change * make trace dump for circuit outputs cleaner * remove unwanted code * increase felt dict count always during get() * doc function + merge main * reviews * use elemts stride for offseting u384 structs * forgot to update one stride --------- Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com>
1 parent b63ab1b commit 0a05bba

File tree

13 files changed

+443
-290
lines changed

13 files changed

+443
-290
lines changed

Cargo.lock

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

debug_utils/sierra-emu/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ cairo-lang-utils.workspace = true
2323
clap = { version = "4.5.26", features = ["derive"] }
2424
k256 = "0.13.4"
2525
keccak = "0.1.5"
26+
num-integer.workspace = true
2627
num-bigint.workspace = true
2728
num-traits.workspace = true
2829
p256 = "0.13.2"

debug_utils/sierra-emu/src/utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ pub fn get_value_from_integer(
5454
CoreTypeConcrete::Uint32(_) => Value::U32(value.to_u32().unwrap()),
5555
CoreTypeConcrete::Uint64(_) => Value::U64(value.to_u64().unwrap()),
5656
CoreTypeConcrete::Uint128(_) => Value::U128(value.to_u128().unwrap()),
57+
CoreTypeConcrete::BoundedInt(info) => {
58+
let range = &info.range;
59+
Value::BoundedInt {
60+
range: range.lower.clone()..range.upper.clone(),
61+
value,
62+
}
63+
}
64+
CoreTypeConcrete::Felt252(_) => Value::Felt(value.into()),
5765
_ => panic!("cannot get integer value for a non-integer type"),
5866
}
5967
}

debug_utils/sierra-emu/src/value.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ pub enum Value {
2727
value: BigInt,
2828
},
2929
Circuit(Vec<BigUint>),
30+
CircuitOutputs {
31+
circuits: Vec<BigUint>,
32+
modulus: BigUint,
33+
},
3034
CircuitModulus(BigUint),
31-
CircuitOutputs(Vec<BigUint>),
3235
Enum {
3336
self_ty: ConcreteTypeId,
3437
index: usize,
@@ -173,25 +176,31 @@ impl Value {
173176

174177
// Circuit related types
175178
CoreTypeConcrete::Circuit(selector) => match selector {
176-
CircuitTypeConcrete::Circuit(_) => matches!(self, Self::Circuit(_)),
177-
CircuitTypeConcrete::CircuitData(_) => matches!(self, Self::Circuit(_)),
178-
CircuitTypeConcrete::CircuitOutputs(_) => matches!(self, Self::CircuitOutputs(_)),
179-
CircuitTypeConcrete::CircuitInput(_) => matches!(self, Self::Unit),
180-
CircuitTypeConcrete::CircuitInputAccumulator(_) => matches!(self, Self::Circuit(_)),
179+
CircuitTypeConcrete::Circuit(_)
180+
| CircuitTypeConcrete::CircuitData(_)
181+
| CircuitTypeConcrete::CircuitInputAccumulator(_) => {
182+
matches!(self, Self::Circuit(_))
183+
}
184+
CircuitTypeConcrete::CircuitOutputs(_) => {
185+
matches!(self, Self::CircuitOutputs { .. })
186+
}
181187
CircuitTypeConcrete::CircuitModulus(_) => matches!(self, Self::CircuitModulus(_)),
182188
CircuitTypeConcrete::U96Guarantee(_) => matches!(self, Self::U128(_)),
183-
CircuitTypeConcrete::CircuitDescriptor(_)
184-
| CircuitTypeConcrete::CircuitFailureGuarantee(_)
185-
| CircuitTypeConcrete::AddMod(_)
189+
CircuitTypeConcrete::CircuitInput(_) => {
190+
matches!(self, Self::Struct(_))
191+
}
192+
CircuitTypeConcrete::U96LimbsLessThanGuarantee(_) => {
193+
matches!(self, Self::Struct(_))
194+
}
195+
CircuitTypeConcrete::AddMod(_)
186196
| CircuitTypeConcrete::MulMod(_)
197+
| CircuitTypeConcrete::CircuitDescriptor(_)
198+
| CircuitTypeConcrete::CircuitFailureGuarantee(_)
187199
| CircuitTypeConcrete::AddModGate(_)
188200
| CircuitTypeConcrete::CircuitPartialOutputs(_)
189201
| CircuitTypeConcrete::InverseGate(_)
190202
| CircuitTypeConcrete::MulModGate(_)
191-
| CircuitTypeConcrete::SubModGate(_)
192-
| CircuitTypeConcrete::U96LimbsLessThanGuarantee(_) => {
193-
matches!(self, Self::Unit)
194-
}
203+
| CircuitTypeConcrete::SubModGate(_) => matches!(self, Self::Unit),
195204
},
196205
CoreTypeConcrete::Const(info) => self.is(registry, &info.inner_ty),
197206
CoreTypeConcrete::EcOp(_) => matches!(self, Self::Unit),

debug_utils/sierra-emu/src/vm/cast.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ fn eval_downcast(
3636
let [value] = get_numeric_args_as_bigints(&args[1..]).try_into().unwrap();
3737

3838
let int_ty = registry.get_type(&info.to_ty).unwrap();
39+
3940
let range = info.to_range.lower.clone()..info.to_range.upper.clone();
4041
if range.contains(&value) {
4142
EvalAction::NormalBranch(

0 commit comments

Comments
 (0)