From 0cde3056474a475ac989d38c27edf6d28bdf6921 Mon Sep 17 00:00:00 2001 From: msaug Date: Thu, 3 Aug 2023 13:24:02 +0200 Subject: [PATCH] dev: update scarb & use asdf version management --- .tool-versions | 1 + README.md | 5 ++++- Scarb.toml | 10 +++++++++- src/memory.cairo | 12 ++++++------ src/stack.cairo | 14 +++++++------- 5 files changed, 27 insertions(+), 15 deletions(-) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 000000000..c7375f1a0 --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +scarb 0.6.0-alpha.2 diff --git a/README.md b/README.md index c64ee6ade..51731eed9 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,10 @@ This repository is a rewrite of ### Installation -- Install [Scarb](https://docs.swmansion.com/scarb) +- Install [Scarb](https://docs.swmansion.com/scarb). To make sure your version + always matches the one used by Kakarot, you can install Scarb + [via asdk](https://docs.swmansion.com/scarb/download#install-via-asdf). + - [Fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo) the repository and clone your fork (`git clone https://github.com//kakarot-ssj`) diff --git a/Scarb.toml b/Scarb.toml index 21c8c862b..850bd3668 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -1,4 +1,12 @@ [package] -cairo-version = "2.0.2" +cairo-version = "2.1.0-rc2" name = "kakarot" version = "0.1.0" +readme = "README.md" +repository = "https://github.com/kkrt-labs/kakarot-ssj/" +license-file = "LICENSE" + +[dependencies] +starknet = "2.1.0-rc2" + +[[tool.starknet-contract]] diff --git a/src/memory.cairo b/src/memory.cairo index fbceee73d..5325b1d86 100644 --- a/src/memory.cairo +++ b/src/memory.cairo @@ -6,7 +6,7 @@ use clone::Clone; use dict::Felt252Dict; use dict::Felt252DictTrait; use integer::{ - u32_safe_divmod, u32_as_non_zero, u128_safe_divmod, u128_as_non_zero, u256_safe_divmod, + u32_safe_divmod, u32_as_non_zero, u128_safe_divmod, u128_as_non_zero, u256_safe_div_rem, u256_as_non_zero }; use traits::{TryInto, Into}; @@ -148,11 +148,11 @@ impl MemoryImpl of MemoryTrait { // Split the 2 input bytes16 chunks at offset_in_chunk. - let (el_hh, el_hl) = u256_safe_divmod( + let (el_hh, el_hl) = u256_safe_div_rem( u256 { low: element.high, high: 0 }, u256_as_non_zero(mask_c) ); - let (el_lh, el_ll) = u256_safe_divmod( + let (el_lh, el_ll) = u256_safe_div_rem( u256 { low: element.low, high: 0 }, u256_as_non_zero(mask_c) ); @@ -209,8 +209,8 @@ impl MemoryImpl of MemoryTrait { // Special case: within the same word. if chunk_index_i == chunk_index_f { let w: u128 = self.items.get(offset_in_chunk_i.into()); - let (w_h, w_l) = u256_safe_divmod(u256 { low: w, high: 0 }, u256_as_non_zero(mask_i)); - let (_, w_ll) = u256_safe_divmod(w_l, u256_as_non_zero(mask_f)); + let (w_h, w_l) = u256_safe_div_rem(u256 { low: w, high: 0 }, u256_as_non_zero(mask_i)); + let (_, w_ll) = u256_safe_div_rem(w_l, u256_as_non_zero(mask_f)); let x = helpers::load_word(elements.len(), elements); let new_w: u128 = (w_h * mask_i + x.into() * mask_f + w_ll).try_into().unwrap(); self.items.insert(chunk_index_i.into(), new_w); @@ -311,7 +311,7 @@ impl MemoryImpl of MemoryTrait { // Compute element words let w0_l: u256 = w0.into() % mask; - let (w1_h, w1_l): (u256, u256) = u256_safe_divmod(w1.into(), u256_as_non_zero(mask)); + let (w1_h, w1_l): (u256, u256) = u256_safe_div_rem(w1.into(), u256_as_non_zero(mask)); let w2_h: u256 = w2.into() / mask; let el_h: u128 = (w0_l * mask_c + w1_h).try_into().unwrap(); let el_l: u128 = (w1_l * mask_c + w2_h).try_into().unwrap(); diff --git a/src/stack.cairo b/src/stack.cairo index ac3e693c1..8ca394c0e 100644 --- a/src/stack.cairo +++ b/src/stack.cairo @@ -27,7 +27,7 @@ use nullable::{nullable_from_box, NullableTrait}; use kakarot::errors; -// This should be in the corelib +// TODO remove this trait once merged in corelib trait NullableTraitExt { fn new(value: T) -> Nullable; } @@ -160,12 +160,12 @@ impl StackImpl of StackTrait { if index >= self.len() { panic_with_felt252('Kakarot: StackUnderflow'); } - let position_0 = self.len() - 1; - let position_item = position_0 - index; - let top_item = self.items.get(position_0.into()); - let swapped_item = self.items.get(position_item.into()); - self.items.insert(position_0.into(), swapped_item.into()); - self.items.insert(position_item.into(), top_item.into()); + let position_0: felt252 = (self.len() - 1).into(); + let position_item: felt252 = position_0 - index.into(); + let top_item = self.items.get(position_0); + let swapped_item = self.items.get(position_item); + self.items.insert(position_0, swapped_item.into()); + self.items.insert(position_item, top_item.into()); } /// Returns the length of the stack.