Skip to content

Commit

Permalink
dev: update scarb & use asdf version management (#48)
Browse files Browse the repository at this point in the history
* dev: update scarb & use asdf version management

* fix: remove specific scarb version from CI (read from .tool-versions)

* fix: typo
  • Loading branch information
enitrat committed Aug 3, 2023
1 parent c8887b8 commit edd5549
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 17 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: software-mansion/setup-scarb@v1
with:
scarb-version: "0.5.2"
- run: scarb fmt --check
- run: scarb build
- run: scarb test
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
scarb 0.6.0-alpha.2
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 asdf](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/<YOUR_USERNAME>/kakarot-ssj`)
Expand Down
10 changes: 9 additions & 1 deletion Scarb.toml
Original file line number Diff line number Diff line change
@@ -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]]
12 changes: 6 additions & 6 deletions src/memory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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)
);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 7 additions & 7 deletions src/stack.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
fn new(value: T) -> Nullable<T>;
}
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit edd5549

Please sign in to comment.