From fb5dc623e911093a8afeca576db88fc00d35e63a Mon Sep 17 00:00:00 2001 From: Bal7hazar Date: Thu, 30 Jan 2025 10:02:26 +0100 Subject: [PATCH] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Upgrade=20cairo=20and=20do?= =?UTF-8?q?jo=20versions=20(#120)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ci.yml | 22 ++- .tool-versions | 2 +- Scarb.lock | 14 +- Scarb.toml | 12 +- crates/Scarb.toml | 2 + crates/algebra/Scarb.toml | 2 + crates/algebra/src/matrix.cairo | 43 ++--- crates/algebra/src/vec2.cairo | 12 +- crates/algebra/src/vector.cairo | 31 +--- crates/defi/Scarb.toml | 3 +- crates/defi/src/auction/vrgda.cairo | 2 +- crates/map/Scarb.toml | 3 +- crates/map/src/finders/astar.cairo | 12 +- crates/map/src/finders/dfs.cairo | 2 +- crates/map/src/finders/finder.cairo | 26 +-- crates/map/src/finders/greedy.cairo | 8 +- crates/map/src/generators/digger.cairo | 8 +- crates/map/src/generators/mazer.cairo | 4 +- crates/map/src/helpers/heap.cairo | 36 ++-- crates/map/src/helpers/power.cairo | 239 ++++++------------------- crates/map/src/hex.cairo | 13 +- crates/random/Scarb.toml | 3 +- crates/random/src/deck.cairo | 2 +- crates/rating/Scarb.toml | 3 +- crates/rating/src/elo.cairo | 10 +- crates/security/Scarb.toml | 3 +- crates/security/src/commitment.cairo | 2 +- 27 files changed, 190 insertions(+), 329 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 631a53e2..fb53e4b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,8 +7,8 @@ on: pull_request: env: - DOJO_VERSION: v1.0.1 - SCARB_VERSION: 2.8.4 + DOJO_VERSION: v1.1.2 + SCARB_VERSION: 2.9.2 jobs: check: @@ -40,6 +40,9 @@ jobs: name: Test origami_algebra steps: - uses: actions/checkout@v4 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} - uses: ./.github/actions/setup - name: Test run: sozo test --package origami_algebra @@ -51,6 +54,9 @@ jobs: name: Test origami_defi steps: - uses: actions/checkout@v4 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} - uses: ./.github/actions/setup - name: Test run: sozo test --package origami_defi @@ -62,6 +68,9 @@ jobs: name: Test origami_map steps: - uses: actions/checkout@v4 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} - uses: ./.github/actions/setup - name: Test run: sozo test --package origami_map @@ -73,6 +82,9 @@ jobs: name: Test origami_random steps: - uses: actions/checkout@v4 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} - uses: ./.github/actions/setup - name: Test run: sozo test --package origami_random @@ -84,6 +96,9 @@ jobs: name: Test origami_rating steps: - uses: actions/checkout@v4 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} - uses: ./.github/actions/setup - name: Test run: sozo test --package origami_rating @@ -95,6 +110,9 @@ jobs: name: Test origami_security steps: - uses: actions/checkout@v4 + - uses: software-mansion/setup-scarb@v1 + with: + scarb-version: ${{ env.SCARB_VERSION }} - uses: ./.github/actions/setup - name: Test run: sozo test --package origami_security diff --git a/.tool-versions b/.tool-versions index ff547533..f6645f9f 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1 +1 @@ -scarb 2.8.4 +scarb 2.9.2 diff --git a/Scarb.lock b/Scarb.lock index 8cea8d6f..71bd8d79 100644 --- a/Scarb.lock +++ b/Scarb.lock @@ -4,34 +4,34 @@ version = 1 [[package]] name = "cubit" version = "1.3.0" -source = "git+https://github.com/bal7hazar/cubit?branch=cairo-2.8.4#6bce623d5c735c097be47a4045c0e0432bad38e7" +source = "git+https://github.com/bengineer42/cubit?branch=bump-cairo-gt-2.8#32a20af893b3e26e6f5cf436c509457d6500ca5c" [[package]] name = "origami_algebra" -version = "1.0.0-rc.2" +version = "1.1.2" dependencies = [ "cubit", ] [[package]] name = "origami_defi" -version = "1.0.0-rc.2" +version = "1.1.2" dependencies = [ "cubit", ] [[package]] name = "origami_map" -version = "1.0.0-rc.2" +version = "1.1.2" [[package]] name = "origami_random" -version = "1.0.0-rc.2" +version = "1.1.2" [[package]] name = "origami_rating" -version = "1.0.0-rc.2" +version = "1.1.2" [[package]] name = "origami_security" -version = "1.0.0-rc.2" +version = "1.1.2" diff --git a/Scarb.toml b/Scarb.toml index bd24873b..6161a97c 100644 --- a/Scarb.toml +++ b/Scarb.toml @@ -9,12 +9,12 @@ members = [ ] [workspace.package] -version = "1.0.0-rc.2" +version = "1.1.2" +edition = "2024_07" [workspace.dependencies] -dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.0.1" } +dojo = { git = "https://github.com/dojoengine/dojo", tag = "v1.1.2" } # dojo = { path = "../dojo/crates/dojo-core" } -cubit = { git = "https://github.com/bal7hazar/cubit", branch = "cairo-2.8.4" } -starknet = "^2.8.4" -cairo_test = "^2.8.4" -# Scripts are not supported for virtual workspaces. +cubit = { git = "https://github.com/bengineer42/cubit", branch = "bump-cairo-gt-2.8" } +starknet = "^2.9.2" +cairo_test = "^2.9.2" diff --git a/crates/Scarb.toml b/crates/Scarb.toml index 8b2cb66d..ed530c66 100644 --- a/crates/Scarb.toml +++ b/crates/Scarb.toml @@ -1,6 +1,7 @@ [package] name = "origami" version.workspace = true +edition.workspace = true authors.workspace = true description.workspace = true homepage = "https://github.com/dojoengine/origami/tree/main/crates" @@ -8,3 +9,4 @@ homepage = "https://github.com/dojoengine/origami/tree/main/crates" [dependencies] cubit.workspace = true dojo.workspace = true +cairo_test.workspace = true diff --git a/crates/algebra/Scarb.toml b/crates/algebra/Scarb.toml index 96fad9d7..8f84218b 100644 --- a/crates/algebra/Scarb.toml +++ b/crates/algebra/Scarb.toml @@ -1,6 +1,7 @@ [package] name = "origami_algebra" version.workspace = true +edition.workspace = true description = "Algebra library for Dojo based games." homepage = "https://github.com/dojoengine/origami/tree/main/crates/algebra" @@ -9,3 +10,4 @@ homepage = "https://github.com/dojoengine/origami/tree/main/crates/algebra" [dependencies] cubit.workspace = true +cairo_test.workspace = true diff --git a/crates/algebra/src/matrix.cairo b/crates/algebra/src/matrix.cairo index 6d4e9528..55fa262c 100644 --- a/crates/algebra/src/matrix.cairo +++ b/crates/algebra/src/matrix.cairo @@ -1,4 +1,4 @@ -use zeroable::Zeroable; +use core::num::traits::Zero; use core::ops::{AddAssign, SubAssign}; @@ -10,9 +10,9 @@ struct Matrix { } mod errors { - const INVALID_INDEX: felt252 = 'Matrix: index out of bounds'; - const INVALID_DIMENSION: felt252 = 'Matrix: invalid dimension'; - const INVALID_MATRIX_INVERSION: felt252 = 'Matrix: matrix not invertible'; + pub const INVALID_INDEX: felt252 = 'Matrix: index out of bounds'; + pub const INVALID_DIMENSION: felt252 = 'Matrix: invalid dimension'; + pub const INVALID_MATRIX_INVERSION: felt252 = 'Matrix: matrix not invertible'; } trait MatrixTrait { @@ -38,7 +38,7 @@ impl MatrixImpl< +Sub, +SubAssign, +Neg, - +Zeroable, + +Zero, +Copy, +Drop, > of MatrixTrait { @@ -102,7 +102,7 @@ impl MatrixImpl< return (self.get(0, 0) * self.get(1, 1)) - (self.get(0, 1) * self.get(1, 0)); } - let mut det: T = Zeroable::zero(); + let mut det: T = Zero::zero(); let mut col: u8 = 0; loop { if col >= self.cols { @@ -166,7 +166,7 @@ impl MatrixAdd< +Sub, +SubAssign, +Neg, - +Zeroable, + +Zero, +Copy, +Drop, > of Add> { @@ -198,7 +198,7 @@ impl MatrixSub< +Sub, +SubAssign, +Neg, - +Zeroable, + +Zero, +Copy, +Drop, > of Sub> { @@ -230,7 +230,7 @@ impl MatrixMul< +Sub, +SubAssign, +Neg, - +Zeroable, + +Zero, +Copy, +Drop, > of Mul> { @@ -248,7 +248,7 @@ impl MatrixMul< let row = index / rhs.cols; let col = index % rhs.cols; - let mut sum: T = Zeroable::zero(); + let mut sum: T = Zero::zero(); let mut k: u8 = 0; loop { if k == lhs.cols { @@ -268,30 +268,7 @@ impl MatrixMul< #[cfg(test)] mod tests { - use core::traits::TryInto; use super::{Matrix, MatrixTrait}; - use debug::PrintTrait; - - impl I128Zeroable of Zeroable { - fn zero() -> i128 { - 0 - } - fn is_zero(self: i128) -> bool { - self == 0 - } - fn is_non_zero(self: i128) -> bool { - self != 0 - } - } - - // impl I128Div of Div { - // fn div(lhs: i128, rhs: i128) -> i128 { - // let lhs_u256: u256 = Into::::into(lhs.into()); - // let rhs_u256: u256 = Into::::into(rhs.into()); - // let div: felt252 = (lhs_u256 / rhs_u256).try_into().unwrap(); - // div.try_into().unwrap() - // } - // } #[test] fn test_matrix_get() { diff --git a/crates/algebra/src/vec2.cairo b/crates/algebra/src/vec2.cairo index 306d2724..729dc3c9 100644 --- a/crates/algebra/src/vec2.cairo +++ b/crates/algebra/src/vec2.cairo @@ -1,8 +1,8 @@ -use cubit::f128::types::fixed::{Fixed, FixedTrait, ONE_u128}; +use cubit::f128::types::fixed::{FixedTrait, ONE_u128}; struct Vec2 { x: T, - y: T + y: T, } impl Vec2Copy> of Copy>; @@ -78,22 +78,22 @@ impl Vec2Impl, impl TDrop: Drop> of Vec2Trait { /// Vec2 -> Vec2 #[inline(always)] fn xx(self: Vec2) -> Vec2 { - Vec2 { x: self.x, y: self.x, } + Vec2 { x: self.x, y: self.x } } #[inline(always)] fn xy(self: Vec2) -> Vec2 { - Vec2 { x: self.x, y: self.y, } + Vec2 { x: self.x, y: self.y } } #[inline(always)] fn yx(self: Vec2) -> Vec2 { - Vec2 { x: self.y, y: self.x, } + Vec2 { x: self.y, y: self.x } } #[inline(always)] fn yy(self: Vec2) -> Vec2 { - Vec2 { x: self.y, y: self.y, } + Vec2 { x: self.y, y: self.y } } } diff --git a/crates/algebra/src/vector.cairo b/crates/algebra/src/vector.cairo index c69e4fcf..7b2e3ee5 100644 --- a/crates/algebra/src/vector.cairo +++ b/crates/algebra/src/vector.cairo @@ -1,4 +1,5 @@ use core::ops::AddAssign; +use core::num::traits::Zero; #[derive(Copy, Drop)] struct Vector { @@ -6,8 +7,8 @@ struct Vector { } mod errors { - const INVALID_INDEX: felt252 = 'Vector: index out of bounds'; - const INVALID_SIZE: felt252 = 'Vector: invalid size'; + pub const INVALID_INDEX: felt252 = 'Vector: index out of bounds'; + pub const INVALID_SIZE: felt252 = 'Vector: invalid size'; } trait VectorTrait { @@ -20,7 +21,7 @@ trait VectorTrait { fn dot(self: Vector, vector: Vector) -> T; } -impl VectorImpl, +AddAssign, +Zeroable, +Copy, +Drop,> of VectorTrait { +impl VectorImpl, +AddAssign, +Zero, +Copy, +Drop> of VectorTrait { fn new(data: Span) -> Vector { Vector { data } } @@ -37,7 +38,7 @@ impl VectorImpl, +AddAssign, +Zeroable, +Copy, +Drop,> // [Check] Dimesions are compatible assert(self.size() == vector.size(), errors::INVALID_SIZE); // [Compute] Dot product in a loop - let mut value = Zeroable::zero(); + let mut value = Zero::zero(); loop { match self.data.pop_front() { Option::Some(x_value) => { @@ -51,7 +52,7 @@ impl VectorImpl, +AddAssign, +Zeroable, +Copy, +Drop,> } impl VectorAdd< - T, +Mul, +AddAssign, +Add, +Zeroable, +Copy, +Drop, + T, +Mul, +AddAssign, +Add, +Zero, +Copy, +Drop, > of Add> { fn add(mut lhs: Vector, mut rhs: Vector) -> Vector { // [Check] Dimesions are compatible @@ -71,7 +72,7 @@ impl VectorAdd< } impl VectorSub< - T, +Mul, +AddAssign, +Sub, +Zeroable, +Copy, +Drop, + T, +Mul, +AddAssign, +Sub, +Zero, +Copy, +Drop, > of Sub> { fn sub(mut lhs: Vector, mut rhs: Vector) -> Vector { // [Check] Dimesions are compatible @@ -92,26 +93,8 @@ impl VectorSub< #[cfg(test)] mod tests { - // Core imports - - use debug::PrintTrait; - - // Local imports - use super::{Vector, VectorTrait}; - impl I128Zeroable of Zeroable { - fn zero() -> i128 { - 0 - } - fn is_zero(self: i128) -> bool { - self == 0 - } - fn is_non_zero(self: i128) -> bool { - self != 0 - } - } - #[test] fn test_vector_get() { let mut vector: Vector = VectorTrait::new(array![1, 2, 3, 4].span()); diff --git a/crates/defi/Scarb.toml b/crates/defi/Scarb.toml index d08b5e3a..f3edd6d8 100644 --- a/crates/defi/Scarb.toml +++ b/crates/defi/Scarb.toml @@ -1,10 +1,11 @@ [package] name = "origami_defi" version.workspace = true +edition.workspace = true description = "DeFi library for Dojo based games." homepage = "https://github.com/dojoengine/origami/tree/main/crates/defi" -edition = "2024_07" [dependencies] cubit.workspace = true starknet.workspace = true +cairo_test.workspace = true diff --git a/crates/defi/src/auction/vrgda.cairo b/crates/defi/src/auction/vrgda.cairo index 008774ce..6babdd3f 100644 --- a/crates/defi/src/auction/vrgda.cairo +++ b/crates/defi/src/auction/vrgda.cairo @@ -87,7 +87,7 @@ pub struct LogisticVRGDA { pub target_price: Fixed, pub decay_constant: Fixed, pub max_sellable: Fixed, - pub time_scale: Fixed, // target time to sell 46% of units + pub time_scale: Fixed // target time to sell 46% of units } impl LogisticVRGDAVarsImpl of VRGDAVarsTrait { diff --git a/crates/map/Scarb.toml b/crates/map/Scarb.toml index fcf770fe..04fb0733 100644 --- a/crates/map/Scarb.toml +++ b/crates/map/Scarb.toml @@ -1,8 +1,9 @@ [package] name = "origami_map" version.workspace = true +edition.workspace = true description = "Maps library for Dojo based games." homepage = "https://github.com/dojoengine/origami/tree/main/crates/map" -edition = "2024_07" [dependencies] +cairo_test.workspace = true diff --git a/crates/map/src/finders/astar.cairo b/crates/map/src/finders/astar.cairo index 6c19fd07..2bfe727a 100644 --- a/crates/map/src/finders/astar.cairo +++ b/crates/map/src/finders/astar.cairo @@ -91,7 +91,7 @@ pub impl Astar of AstarTrait { height: u8, position: u8, direction: Direction, - ref visited: Felt252Dict + ref visited: Felt252Dict, ) -> bool { let (x, y) = (position % width, position / width); match direction { @@ -121,16 +121,14 @@ pub impl Astar of AstarTrait { /// # Effects /// * Update the heap with the neighbor node #[inline] - fn assess( - width: u8, neighbor_position: u8, current: Node, target: Node, ref heap: Heap, - ) { + fn assess(width: u8, neighbor_position: u8, current: Node, target: Node, ref heap: Heap) { let distance = Finder::manhattan(current.position, neighbor_position, width); let neighbor_gcost = current.gcost + distance; let neighbor_hcost = Finder::manhattan(neighbor_position, target.position, width); let mut neighbor = match heap.get(neighbor_position.into()) { Option::Some(node) => node, Option::None => NodeTrait::new( - neighbor_position, current.position, neighbor_gcost, neighbor_hcost + neighbor_position, current.position, neighbor_gcost, neighbor_hcost, ), }; if neighbor_gcost < neighbor.gcost || !heap.contains(neighbor.position) { @@ -218,7 +216,7 @@ mod test { assert_eq!( path, array![170, 171, 172, 154, 136, 118, 117, 116, 115, 114, 113, 112, 94, 93, 75, 74, 56] - .span() + .span(), ); } @@ -272,7 +270,7 @@ mod test { 55, 56, ] - .span() + .span(), ); } } diff --git a/crates/map/src/finders/dfs.cairo b/crates/map/src/finders/dfs.cairo index 16445a83..d8032cd0 100644 --- a/crates/map/src/finders/dfs.cairo +++ b/crates/map/src/finders/dfs.cairo @@ -59,7 +59,7 @@ pub impl DepthFirstSearch of DepthFirstSearchTrait { current: Node, target: Node, ref visited: Felt252Dict, - ref parents: Felt252Dict + ref parents: Felt252Dict, ) -> bool { // [Check] If the current node has already been visited, return false if visited.get(current.position.into()) { diff --git a/crates/map/src/finders/finder.cairo b/crates/map/src/finders/finder.cairo index 19bbb13b..74e659dc 100644 --- a/crates/map/src/finders/finder.cairo +++ b/crates/map/src/finders/finder.cairo @@ -31,7 +31,7 @@ pub impl Finder of FinderTrait { height: u8, position: u8, direction: Direction, - ref visited: Felt252Dict + ref visited: Felt252Dict, ) -> bool { let (x, y) = (position % width, position / width); match direction { @@ -190,16 +190,16 @@ mod test { let position = 0; let mut visited: Felt252Dict = Default::default(); assert_eq!( - Finder::check(grid, width, height, position, Direction::North, ref visited), true + Finder::check(grid, width, height, position, Direction::North, ref visited), true, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::East, ref visited), false + Finder::check(grid, width, height, position, Direction::East, ref visited), false, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::South, ref visited), false + Finder::check(grid, width, height, position, Direction::South, ref visited), false, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::West, ref visited), true + Finder::check(grid, width, height, position, Direction::West, ref visited), true, ); } @@ -214,16 +214,16 @@ mod test { let position = 1; let mut visited: Felt252Dict = Default::default(); assert_eq!( - Finder::check(grid, width, height, position, Direction::North, ref visited), false + Finder::check(grid, width, height, position, Direction::North, ref visited), false, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::East, ref visited), true + Finder::check(grid, width, height, position, Direction::East, ref visited), true, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::South, ref visited), false + Finder::check(grid, width, height, position, Direction::South, ref visited), false, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::West, ref visited), true + Finder::check(grid, width, height, position, Direction::West, ref visited), true, ); } @@ -238,16 +238,16 @@ mod test { let position = 4; let mut visited: Felt252Dict = Default::default(); assert_eq!( - Finder::check(grid, width, height, position, Direction::North, ref visited), true + Finder::check(grid, width, height, position, Direction::North, ref visited), true, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::East, ref visited), false + Finder::check(grid, width, height, position, Direction::East, ref visited), false, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::South, ref visited), false + Finder::check(grid, width, height, position, Direction::South, ref visited), false, ); assert_eq!( - Finder::check(grid, width, height, position, Direction::West, ref visited), true + Finder::check(grid, width, height, position, Direction::West, ref visited), true, ); } diff --git a/crates/map/src/finders/greedy.cairo b/crates/map/src/finders/greedy.cairo index b1054b0a..6ae7e25c 100644 --- a/crates/map/src/finders/greedy.cairo +++ b/crates/map/src/finders/greedy.cairo @@ -84,9 +84,7 @@ pub impl Greedy of GreedyTrait { /// # Effects /// * Update the heap with the neighbor node #[inline] - fn assess( - width: u8, neighbor_position: u8, current: Node, target: Node, ref heap: Heap, - ) { + fn assess(width: u8, neighbor_position: u8, current: Node, target: Node, ref heap: Heap) { let neighbor_hcost = Finder::manhattan(neighbor_position, target.position, width); let mut neighbor = match heap.get(neighbor_position.into()) { Option::Some(node) => node, @@ -176,9 +174,9 @@ mod test { 93, 75, 74, - 56 + 56, ] - .span() + .span(), ); } } diff --git a/crates/map/src/generators/digger.cairo b/crates/map/src/generators/digger.cairo index 381d7895..a499e5ca 100644 --- a/crates/map/src/generators/digger.cairo +++ b/crates/map/src/generators/digger.cairo @@ -25,7 +25,7 @@ pub impl Digger of DiggerTrait { /// * The grid with the maze to the exit #[inline] fn maze( - width: u8, height: u8, order: u8, start: u8, mut grid: felt252, mut seed: felt252 + width: u8, height: u8, order: u8, start: u8, mut grid: felt252, mut seed: felt252, ) -> felt252 { // [Check] Position is not a corner and is on an edge Asserter::assert_not_corner(width, height, start); @@ -62,7 +62,7 @@ pub impl Digger of DiggerTrait { /// * The grid with the maze to the exit #[inline] fn corridor( - width: u8, height: u8, order: u8, start: u8, grid: felt252, mut seed: felt252 + width: u8, height: u8, order: u8, start: u8, grid: felt252, mut seed: felt252, ) -> felt252 { // [Check] Position is not a corner and is on an edge Asserter::assert_not_corner(width, height, start); @@ -107,7 +107,7 @@ pub impl Digger of DiggerTrait { grid: felt252, ref stop: bool, ref maze: felt252, - ref seed: felt252 + ref seed: felt252, ) { // [Check] Stop criteria, the position collides with the grid if Bitmap::get(grid, start) == 1 { @@ -165,7 +165,7 @@ pub impl Digger of DiggerTrait { order: u8, position: u8, direction: Direction, - stop: bool + stop: bool, ) -> bool { !stop && Mazer::check(grid, width, height, order, position, direction) } diff --git a/crates/map/src/generators/mazer.cairo b/crates/map/src/generators/mazer.cairo index 89e28fc0..69120b13 100644 --- a/crates/map/src/generators/mazer.cairo +++ b/crates/map/src/generators/mazer.cairo @@ -56,7 +56,7 @@ pub impl Mazer of MazerTrait { start: u8, ref grid: felt252, ref maze: felt252, - ref seed: felt252 + ref seed: felt252, ) { // [Check] Stop criteria, the position collides with the original grid if Bitmap::get(grid, start) == 1 { @@ -109,7 +109,7 @@ pub impl Mazer of MazerTrait { /// * Whether the position can be visited in the specified direction #[inline] fn check( - maze: felt252, width: u8, height: u8, order: u8, position: u8, direction: Direction + maze: felt252, width: u8, height: u8, order: u8, position: u8, direction: Direction, ) -> bool { // [Check] Order is valid assert(order <= 1, errors::MAZER_INVALID_ORDER); diff --git a/crates/map/src/helpers/heap.cairo b/crates/map/src/helpers/heap.cairo index 7d09bf81..54eb8dfa 100644 --- a/crates/map/src/helpers/heap.cairo +++ b/crates/map/src/helpers/heap.cairo @@ -124,7 +124,7 @@ pub struct Heap { pub impl HeapImpl, +PartialOrd, +Copy, +Drop> of HeapTrait { #[inline] fn new() -> Heap { - Heap { len: 0, keys: Default::default(), data: Default::default(), } + Heap { len: 0, keys: Default::default(), data: Default::default() } } #[inline] @@ -288,7 +288,7 @@ mod tests { #[test] fn test_heap_add() { let mut heap: Heap = HeapTrait::new(); - let node: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; + let node: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; heap.add(node); assert!(!heap.is_empty()); } @@ -296,7 +296,7 @@ mod tests { #[test] fn test_heap_contains() { let mut heap: Heap = HeapTrait::new(); - let node: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; + let node: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; heap.add(node); assert!(heap.contains(node.position)); } @@ -304,16 +304,16 @@ mod tests { #[test] fn test_heap_not_contains() { let mut heap: Heap = HeapTrait::new(); - let node: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; + let node: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; assert!(!heap.contains(node.position)); } #[test] fn test_heap_pop_front_sorted() { let mut heap: Heap = HeapTrait::new(); - let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; - let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2, }; - let third: Node = Node { position: 3, source: 3, gcost: 3, hcost: 3, }; + let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; + let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2 }; + let third: Node = Node { position: 3, source: 3, gcost: 3, hcost: 3 }; heap.add(first); heap.add(second); heap.add(third); @@ -325,9 +325,9 @@ mod tests { #[test] fn test_heap_pop_front_reversed() { let mut heap: Heap = HeapTrait::new(); - let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; - let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2, }; - let third: Node = Node { position: 3, source: 3, gcost: 3, hcost: 3, }; + let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; + let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2 }; + let third: Node = Node { position: 3, source: 3, gcost: 3, hcost: 3 }; heap.add(third); heap.add(second); heap.add(first); @@ -339,8 +339,8 @@ mod tests { #[test] fn test_heap_swap() { let mut heap: Heap = HeapTrait::new(); - let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; - let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2, }; + let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; + let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2 }; heap.add(first); heap.add(second); heap.swap(first.key(), second.key()); @@ -354,8 +354,8 @@ mod tests { #[test] fn test_heap_get() { let mut heap: Heap = HeapTrait::new(); - let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; - let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2, }; + let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; + let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2 }; heap.add(first); heap.add(second); assert_eq!(heap.get(first.position).unwrap().position, 1); @@ -368,8 +368,8 @@ mod tests { #[test] fn test_heap_at() { let mut heap: Heap = HeapTrait::new(); - let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; - let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2, }; + let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; + let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2 }; heap.add(first); heap.add(second); assert_eq!(heap.at(first.position).position, 1); @@ -382,8 +382,8 @@ mod tests { #[test] fn test_heap_add_pop_add() { let mut heap: Heap = HeapTrait::new(); - let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1, }; - let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2, }; + let first: Node = Node { position: 1, source: 1, gcost: 1, hcost: 1 }; + let second: Node = Node { position: 2, source: 2, gcost: 2, hcost: 2 }; heap.add(first); heap.add(second); heap.pop_front().unwrap(); diff --git a/crates/map/src/helpers/power.cairo b/crates/map/src/helpers/power.cairo index e03f788a..8d5db289 100644 --- a/crates/map/src/helpers/power.cairo +++ b/crates/map/src/helpers/power.cairo @@ -1,185 +1,62 @@ // Powers of two -const TWO_POWER: [ - u256 - ; 256] = [ - 0x1, - 0x2, - 0x4, - 0x8, - 0x10, - 0x20, - 0x40, - 0x80, - 0x100, - 0x200, - 0x400, - 0x800, - 0x1000, - 0x2000, - 0x4000, - 0x8000, - 0x10000, - 0x20000, - 0x40000, - 0x80000, - 0x100000, - 0x200000, - 0x400000, - 0x800000, - 0x1000000, - 0x2000000, - 0x4000000, - 0x8000000, - 0x10000000, - 0x20000000, - 0x40000000, - 0x80000000, - 0x100000000, - 0x200000000, - 0x400000000, - 0x800000000, - 0x1000000000, - 0x2000000000, - 0x4000000000, - 0x8000000000, - 0x10000000000, - 0x20000000000, - 0x40000000000, - 0x80000000000, - 0x100000000000, - 0x200000000000, - 0x400000000000, - 0x800000000000, - 0x1000000000000, - 0x2000000000000, - 0x4000000000000, - 0x8000000000000, - 0x10000000000000, - 0x20000000000000, - 0x40000000000000, - 0x80000000000000, - 0x100000000000000, - 0x200000000000000, - 0x400000000000000, - 0x800000000000000, - 0x1000000000000000, - 0x2000000000000000, - 0x4000000000000000, - 0x8000000000000000, - 0x10000000000000000, - 0x20000000000000000, - 0x40000000000000000, - 0x80000000000000000, - 0x100000000000000000, - 0x200000000000000000, - 0x400000000000000000, - 0x800000000000000000, - 0x1000000000000000000, - 0x2000000000000000000, - 0x4000000000000000000, - 0x8000000000000000000, - 0x10000000000000000000, - 0x20000000000000000000, - 0x40000000000000000000, - 0x80000000000000000000, - 0x100000000000000000000, - 0x200000000000000000000, - 0x400000000000000000000, - 0x800000000000000000000, - 0x1000000000000000000000, - 0x2000000000000000000000, - 0x4000000000000000000000, - 0x8000000000000000000000, - 0x10000000000000000000000, - 0x20000000000000000000000, - 0x40000000000000000000000, - 0x80000000000000000000000, - 0x100000000000000000000000, - 0x200000000000000000000000, - 0x400000000000000000000000, - 0x800000000000000000000000, - 0x1000000000000000000000000, - 0x2000000000000000000000000, - 0x4000000000000000000000000, - 0x8000000000000000000000000, - 0x10000000000000000000000000, - 0x20000000000000000000000000, - 0x40000000000000000000000000, - 0x80000000000000000000000000, - 0x100000000000000000000000000, - 0x200000000000000000000000000, - 0x400000000000000000000000000, - 0x800000000000000000000000000, - 0x1000000000000000000000000000, - 0x2000000000000000000000000000, - 0x4000000000000000000000000000, - 0x8000000000000000000000000000, - 0x10000000000000000000000000000, - 0x20000000000000000000000000000, - 0x40000000000000000000000000000, - 0x80000000000000000000000000000, - 0x100000000000000000000000000000, - 0x200000000000000000000000000000, - 0x400000000000000000000000000000, - 0x800000000000000000000000000000, - 0x1000000000000000000000000000000, - 0x2000000000000000000000000000000, - 0x4000000000000000000000000000000, - 0x8000000000000000000000000000000, - 0x10000000000000000000000000000000, - 0x20000000000000000000000000000000, - 0x40000000000000000000000000000000, - 0x80000000000000000000000000000000, - 0x100000000000000000000000000000000, - 0x200000000000000000000000000000000, - 0x400000000000000000000000000000000, - 0x800000000000000000000000000000000, - 0x1000000000000000000000000000000000, - 0x2000000000000000000000000000000000, - 0x4000000000000000000000000000000000, - 0x8000000000000000000000000000000000, - 0x10000000000000000000000000000000000, - 0x20000000000000000000000000000000000, - 0x40000000000000000000000000000000000, - 0x80000000000000000000000000000000000, - 0x100000000000000000000000000000000000, - 0x200000000000000000000000000000000000, - 0x400000000000000000000000000000000000, - 0x800000000000000000000000000000000000, - 0x1000000000000000000000000000000000000, - 0x2000000000000000000000000000000000000, - 0x4000000000000000000000000000000000000, - 0x8000000000000000000000000000000000000, - 0x10000000000000000000000000000000000000, - 0x20000000000000000000000000000000000000, - 0x40000000000000000000000000000000000000, - 0x80000000000000000000000000000000000000, - 0x100000000000000000000000000000000000000, - 0x200000000000000000000000000000000000000, - 0x400000000000000000000000000000000000000, - 0x800000000000000000000000000000000000000, - 0x1000000000000000000000000000000000000000, - 0x2000000000000000000000000000000000000000, - 0x4000000000000000000000000000000000000000, - 0x8000000000000000000000000000000000000000, - 0x10000000000000000000000000000000000000000, - 0x20000000000000000000000000000000000000000, - 0x40000000000000000000000000000000000000000, - 0x80000000000000000000000000000000000000000, - 0x100000000000000000000000000000000000000000, - 0x200000000000000000000000000000000000000000, - 0x400000000000000000000000000000000000000000, - 0x800000000000000000000000000000000000000000, - 0x1000000000000000000000000000000000000000000, - 0x2000000000000000000000000000000000000000000, - 0x4000000000000000000000000000000000000000000, - 0x8000000000000000000000000000000000000000000, - 0x10000000000000000000000000000000000000000000, - 0x20000000000000000000000000000000000000000000, - 0x40000000000000000000000000000000000000000000, - 0x80000000000000000000000000000000000000000000, - 0x100000000000000000000000000000000000000000000, +const TWO_POWER: [u256; 256] = [ + 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, + 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, 0x800000, 0x1000000, + 0x2000000, 0x4000000, 0x8000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000, 0x100000000, + 0x200000000, 0x400000000, 0x800000000, 0x1000000000, 0x2000000000, 0x4000000000, 0x8000000000, + 0x10000000000, 0x20000000000, 0x40000000000, 0x80000000000, 0x100000000000, 0x200000000000, + 0x400000000000, 0x800000000000, 0x1000000000000, 0x2000000000000, 0x4000000000000, + 0x8000000000000, 0x10000000000000, 0x20000000000000, 0x40000000000000, 0x80000000000000, + 0x100000000000000, 0x200000000000000, 0x400000000000000, 0x800000000000000, 0x1000000000000000, + 0x2000000000000000, 0x4000000000000000, 0x8000000000000000, 0x10000000000000000, + 0x20000000000000000, 0x40000000000000000, 0x80000000000000000, 0x100000000000000000, + 0x200000000000000000, 0x400000000000000000, 0x800000000000000000, 0x1000000000000000000, + 0x2000000000000000000, 0x4000000000000000000, 0x8000000000000000000, 0x10000000000000000000, + 0x20000000000000000000, 0x40000000000000000000, 0x80000000000000000000, 0x100000000000000000000, + 0x200000000000000000000, 0x400000000000000000000, 0x800000000000000000000, + 0x1000000000000000000000, 0x2000000000000000000000, 0x4000000000000000000000, + 0x8000000000000000000000, 0x10000000000000000000000, 0x20000000000000000000000, + 0x40000000000000000000000, 0x80000000000000000000000, 0x100000000000000000000000, + 0x200000000000000000000000, 0x400000000000000000000000, 0x800000000000000000000000, + 0x1000000000000000000000000, 0x2000000000000000000000000, 0x4000000000000000000000000, + 0x8000000000000000000000000, 0x10000000000000000000000000, 0x20000000000000000000000000, + 0x40000000000000000000000000, 0x80000000000000000000000000, 0x100000000000000000000000000, + 0x200000000000000000000000000, 0x400000000000000000000000000, 0x800000000000000000000000000, + 0x1000000000000000000000000000, 0x2000000000000000000000000000, 0x4000000000000000000000000000, + 0x8000000000000000000000000000, 0x10000000000000000000000000000, + 0x20000000000000000000000000000, 0x40000000000000000000000000000, + 0x80000000000000000000000000000, 0x100000000000000000000000000000, + 0x200000000000000000000000000000, 0x400000000000000000000000000000, + 0x800000000000000000000000000000, 0x1000000000000000000000000000000, + 0x2000000000000000000000000000000, 0x4000000000000000000000000000000, + 0x8000000000000000000000000000000, 0x10000000000000000000000000000000, + 0x20000000000000000000000000000000, 0x40000000000000000000000000000000, + 0x80000000000000000000000000000000, 0x100000000000000000000000000000000, + 0x200000000000000000000000000000000, 0x400000000000000000000000000000000, + 0x800000000000000000000000000000000, 0x1000000000000000000000000000000000, + 0x2000000000000000000000000000000000, 0x4000000000000000000000000000000000, + 0x8000000000000000000000000000000000, 0x10000000000000000000000000000000000, + 0x20000000000000000000000000000000000, 0x40000000000000000000000000000000000, + 0x80000000000000000000000000000000000, 0x100000000000000000000000000000000000, + 0x200000000000000000000000000000000000, 0x400000000000000000000000000000000000, + 0x800000000000000000000000000000000000, 0x1000000000000000000000000000000000000, + 0x2000000000000000000000000000000000000, 0x4000000000000000000000000000000000000, + 0x8000000000000000000000000000000000000, 0x10000000000000000000000000000000000000, + 0x20000000000000000000000000000000000000, 0x40000000000000000000000000000000000000, + 0x80000000000000000000000000000000000000, 0x100000000000000000000000000000000000000, + 0x200000000000000000000000000000000000000, 0x400000000000000000000000000000000000000, + 0x800000000000000000000000000000000000000, 0x1000000000000000000000000000000000000000, + 0x2000000000000000000000000000000000000000, 0x4000000000000000000000000000000000000000, + 0x8000000000000000000000000000000000000000, 0x10000000000000000000000000000000000000000, + 0x20000000000000000000000000000000000000000, 0x40000000000000000000000000000000000000000, + 0x80000000000000000000000000000000000000000, 0x100000000000000000000000000000000000000000, + 0x200000000000000000000000000000000000000000, 0x400000000000000000000000000000000000000000, + 0x800000000000000000000000000000000000000000, 0x1000000000000000000000000000000000000000000, + 0x2000000000000000000000000000000000000000000, 0x4000000000000000000000000000000000000000000, + 0x8000000000000000000000000000000000000000000, 0x10000000000000000000000000000000000000000000, + 0x20000000000000000000000000000000000000000000, 0x40000000000000000000000000000000000000000000, + 0x80000000000000000000000000000000000000000000, 0x100000000000000000000000000000000000000000000, 0x200000000000000000000000000000000000000000000, 0x400000000000000000000000000000000000000000000, 0x800000000000000000000000000000000000000000000, @@ -293,7 +170,7 @@ mod tests { #[test] fn test_two_power_exp_255() { assert_eq!( - TwoPower::pow(255), 0x8000000000000000000000000000000000000000000000000000000000000000 + TwoPower::pow(255), 0x8000000000000000000000000000000000000000000000000000000000000000, ); } } diff --git a/crates/map/src/hex.cairo b/crates/map/src/hex.cairo index de3595ac..4a627bf0 100644 --- a/crates/map/src/hex.cairo +++ b/crates/map/src/hex.cairo @@ -53,7 +53,7 @@ pub impl HexImpl of HexTrait { self.neighbor_even_y(Direction::NorthWest(())), self.neighbor_even_y(Direction::West(())), self.neighbor_even_y(Direction::SouthWest(())), - self.neighbor_even_y(Direction::SouthEast(())) + self.neighbor_even_y(Direction::SouthEast(())), ]; } return array![ @@ -62,7 +62,7 @@ pub impl HexImpl of HexTrait { self.neighbor(Direction::NorthWest(())), self.neighbor(Direction::West(())), self.neighbor(Direction::SouthWest(())), - self.neighbor(Direction::SouthEast(())) + self.neighbor(Direction::SouthEast(())), ]; } @@ -190,21 +190,22 @@ mod tests { assert(hex_tile.is_neighbor(Hex { col: hex_tile.col + 1, row: hex_tile.row }), 'east'); assert( - hex_tile.is_neighbor(Hex { col: hex_tile.col, row: hex_tile.row + 1 }), 'north east' + hex_tile.is_neighbor(Hex { col: hex_tile.col, row: hex_tile.row + 1 }), 'north east', ); assert( - hex_tile.is_neighbor(Hex { col: hex_tile.col, row: hex_tile.row - 1 }), 'north west' + hex_tile.is_neighbor(Hex { col: hex_tile.col, row: hex_tile.row - 1 }), 'north west', ); assert(hex_tile.is_neighbor(Hex { col: hex_tile.col - 1, row: hex_tile.row }), 'west'); assert( - hex_tile.is_neighbor(Hex { col: hex_tile.col, row: hex_tile.row - 1 }), 'south west' + hex_tile.is_neighbor(Hex { col: hex_tile.col, row: hex_tile.row - 1 }), 'south west', ); assert( - hex_tile.is_neighbor(Hex { col: hex_tile.col + 1, row: hex_tile.row - 1 }), 'south east' + hex_tile.is_neighbor(Hex { col: hex_tile.col + 1, row: hex_tile.row - 1 }), + 'south east', ); } diff --git a/crates/random/Scarb.toml b/crates/random/Scarb.toml index 27519626..afd41258 100644 --- a/crates/random/Scarb.toml +++ b/crates/random/Scarb.toml @@ -1,8 +1,9 @@ [package] name = "origami_random" version.workspace = true +edition.workspace = true description = "Random generator library for Dojo based games." homepage = "https://github.com/dojoengine/origami/tree/main/crates/random" -edition = "2024_07" [dependencies] +cairo_test.workspace = true diff --git a/crates/random/src/deck.cairo b/crates/random/src/deck.cairo index 11236096..63d1c7ba 100644 --- a/crates/random/src/deck.cairo +++ b/crates/random/src/deck.cairo @@ -74,7 +74,7 @@ pub impl DeckImpl of DeckTrait { #[inline(always)] fn new(seed: felt252, number: u32) -> Deck { Deck { - seed, cards: Default::default(), keys: Default::default(), remaining: number, nonce: 0 + seed, cards: Default::default(), keys: Default::default(), remaining: number, nonce: 0, } } diff --git a/crates/rating/Scarb.toml b/crates/rating/Scarb.toml index 57b00a35..2e7ba577 100644 --- a/crates/rating/Scarb.toml +++ b/crates/rating/Scarb.toml @@ -1,8 +1,9 @@ [package] name = "origami_rating" version.workspace = true +edition.workspace = true description = "Rating related algorithm library for Dojo based games." homepage = "https://github.com/dojoengine/origami/tree/main/crates/rating" -edition = "2024_07" [dependencies] +cairo_test.workspace = true diff --git a/crates/rating/src/elo.cairo b/crates/rating/src/elo.cairo index 0fae4480..1b1065a9 100644 --- a/crates/rating/src/elo.cairo +++ b/crates/rating/src/elo.cairo @@ -47,7 +47,7 @@ pub impl EloImpl of EloTrait { C, +Into, >( - rating_a: T, rating_b: T, score: S, k: K + rating_a: T, rating_b: T, score: S, k: K, ) -> (C, bool) { // [Check] Checks against overflow/underflow // Large rating diffs leads to 10 ** rating_diff being too large to fit in a u256 @@ -65,7 +65,7 @@ pub impl EloImpl of EloTrait { // [Info] Order should be less or equal to 77 to fit a u256 let powered: u256 = PrivateTrait::pow(10, order); let rooted: u16 = Sqrt::< - u32 + u32, >::sqrt(Sqrt::::sqrt(Sqrt::::sqrt(Sqrt::::sqrt(powered)))); // [Compute] Change = k * (score - expectedScore) @@ -86,7 +86,7 @@ pub impl EloImpl of EloTrait { #[generate_trait] impl Private of PrivateTrait { fn pow, +Mul, +Div, +Rem, +PartialEq, +Into, +Drop, +Copy>( - base: T, exp: T + base: T, exp: T, ) -> T { if exp == 0_u8.into() { 1_u8.into() @@ -100,9 +100,9 @@ impl Private of PrivateTrait { } fn round_div< - T, +Add, +Sub, +Div, +Rem, +PartialOrd, +Into, +Drop, +Copy + T, +Add, +Sub, +Div, +Rem, +PartialOrd, +Into, +Drop, +Copy, >( - a: T, b: T + a: T, b: T, ) -> T { let remained = a % b; if b - remained <= remained { diff --git a/crates/security/Scarb.toml b/crates/security/Scarb.toml index a2284568..d2204bff 100644 --- a/crates/security/Scarb.toml +++ b/crates/security/Scarb.toml @@ -1,8 +1,9 @@ [package] name = "origami_security" version.workspace = true +edition.workspace = true description = "Security library for Dojo based games." homepage = "https://github.com/dojoengine/origami/tree/main/crates/security" -edition = "2024_07" [dependencies] +cairo_test.workspace = true diff --git a/crates/security/src/commitment.cairo b/crates/security/src/commitment.cairo index 65afee55..c70d22b2 100644 --- a/crates/security/src/commitment.cairo +++ b/crates/security/src/commitment.cairo @@ -3,7 +3,7 @@ use core::num::traits::Zero; #[derive(Copy, Drop, Default, Serde)] pub struct Commitment { - pub hash: felt252 + pub hash: felt252, } /// Errors module.