Skip to content

scarb & snforge upgrade #2570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-starknet-tools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.78.0
toolchain: 1.86.0
components: rustfmt, clippy
override: true
- uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions target_chains/starknet/contracts/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
scarb 2.5.4
starknet-foundry 0.21.0
dojo 0.6.0
starkli 0.2.8
scarb 2.11.1
starknet-foundry 0.38.3
132 changes: 128 additions & 4 deletions target_chains/starknet/contracts/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,122 @@ version = 1

[[package]]
name = "openzeppelin"
version = "0.10.0"
source = "git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.10.0#d77082732daab2690ba50742ea41080eb23299d3"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:320185f3e17cf9fafda88b1ce490f5eaed0bfcc273036b56cd22ce4fb8de628f"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_merkle_tree",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:a39a4ea1582916c637bf7e3aee0832c3fe1ea3a3e39191955e8dc39d08327f9b"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:7e943a2de32ddca4d48e467e52790e380ab1f49c4daddbbbc4634dd930d0243f"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_finance"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:9fa9e91d39b6ccdfa31eef32fdc087cd06c0269cc9c6b86e32d57f5a6997d98b"
dependencies = [
"openzeppelin_access",
"openzeppelin_token",
]

[[package]]
name = "openzeppelin_governance"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:c05add2974b3193c3a5c022b9586a84cf98c5970cdb884dcf201c77dbe359f55"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_introspection"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:34e088ecf19e0b3012481a29f1fbb20e600540cb9a5db1c3002a97ebb7f5a32a"

[[package]]
name = "openzeppelin_merkle_tree"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:a5341705514a3d9beeeb39cf11464111f7355be621639740d2c5006786aa63dc"

[[package]]
name = "openzeppelin_presets"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:4eb098e2ee3ac0e67b6828115a7de62f781418beab767d4e80b54e176808369d"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_introspection",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_security"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:1deb811a239c4f9cc28fc302039e2ffcb19911698a8c612487207448d70d2e6e"

[[package]]
name = "openzeppelin_token"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:33fcb84a1a76d2d3fff9302094ff564f78d45b743548fd7568c130b272473f66"
dependencies = [
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_upgrades"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:36f7a03e7e7111577916aacf31f88ad0053de20f33ee10b0ab3804849c3aa373"

[[package]]
name = "openzeppelin_utils"
version = "1.0.0"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:fd348b31c4a4407add33adc3c2b8f26dca71dbd7431faaf726168f37a91db0c1"

[[package]]
name = "pyth"
Expand All @@ -14,7 +128,17 @@ dependencies = [
"snforge_std",
]

[[package]]
name = "snforge_scarb_plugin"
version = "0.38.3"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:0cd914b547acd96b4cad99a78e95c0eda001d0c280da4969b2161e286079cf46"

[[package]]
name = "snforge_std"
version = "0.21.0"
source = "git+https://github.com/foundry-rs/starknet-foundry?tag=v0.21.0#2996b8c1dd66b2715fc67e69578089f278a46790"
version = "0.38.3"
source = "registry+https://scarbs.xyz/"
checksum = "sha256:d376526fbbe22535ad89ed630b11d6e209f22c50168de6c6430c0591c81c3174"
dependencies = [
"snforge_scarb_plugin",
]
12 changes: 7 additions & 5 deletions target_chains/starknet/contracts/Scarb.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
[package]
name = "pyth"
version = "0.1.0"
edition = "2023_11"
edition = "2024_07"

[dependencies]
starknet = ">=2.5.4"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.21.0" }
starknet = "2.11.1"
openzeppelin = "1.0.0"

[dev-dependencies]
snforge_std = "0.38.3"

[lib]

[[target.starknet-contract]]
build-external-contracts = ["openzeppelin::presets::erc20::ERC20"]
build-external-contracts = ["openzeppelin::presets::erc20::ERC20Upgradeable"]
9 changes: 4 additions & 5 deletions target_chains/starknet/contracts/src/byte_buffer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl DebugByteBuffer of Debug<ByteBuffer> {
Option::Some(v) => { write!(f, "{:?}, ", v).unwrap(); },
Option::None => { break; },
}
};
}
write!(f, "]}}")
}
}
Expand All @@ -45,7 +45,7 @@ pub impl ByteBufferImpl of ByteBufferTrait {
let last: u256 = (*data.at(data.len() - 1)).into();
assert!(
last / one_shift_left_bytes_u256(num_last_bytes) == 0,
"ByteBufferImpl::new: last value is too large"
"ByteBufferImpl::new: last value is too large",
);
}
ByteBuffer { num_last_bytes, data }
Expand Down Expand Up @@ -75,8 +75,7 @@ pub impl ByteBufferImpl of ByteBufferTrait {

#[cfg(test)]
mod tests {
use super::{ByteBuffer, ByteBufferImpl};
use pyth::util::array_try_into;
use super::ByteBufferImpl;

#[test]
fn empty_byte_array() {
Expand Down Expand Up @@ -132,7 +131,7 @@ mod tests {
let value2_31_bytes = 0x2122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f;
let value3_5_bytes = 0x4142434445;
let mut array = ByteBufferImpl::new(
array![value_31_bytes, value2_31_bytes, value3_5_bytes], 5
array![value_31_bytes, value2_31_bytes, value3_5_bytes], 5,
);
assert!(array.len() == 67);
assert!(array.pop_front() == Option::Some((value_31_bytes, 31)));
Expand Down
14 changes: 7 additions & 7 deletions target_chains/starknet/contracts/src/hash.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use super::reader::{Reader, ReaderImpl};
use core::cmp::min;
use core::integer::u128_byte_reverse;
use pyth::util::{
ONE_SHIFT_160, UNEXPECTED_OVERFLOW, UNEXPECTED_ZERO, ONE_SHIFT_64, one_shift_left_bytes_u64,
ONE_SHIFT_160, ONE_SHIFT_64, UNEXPECTED_OVERFLOW, UNEXPECTED_ZERO, one_shift_left_bytes_u64,
u64_byte_reverse,
};
use super::reader::{Reader, ReaderImpl};

/// Allows to push data as big endian to a buffer and apply
/// the keccak256 hash.
Expand Down Expand Up @@ -77,9 +77,9 @@ pub impl HasherImpl of HasherTrait {
u64_byte_reverse(self.last_be) / one_shift_left_bytes_u64(8 - self.num_last_bytes)
};
let hash_le = core::keccak::cairo_keccak(
ref self.inputs_le, last_le, self.num_last_bytes.into()
ref self.inputs_le, last_le, self.num_last_bytes.into(),
);
u256 { low: u128_byte_reverse(hash_le.high), high: u128_byte_reverse(hash_le.low), }
u256 { low: u128_byte_reverse(hash_le.high), high: u128_byte_reverse(hash_le.low) }
}
}

Expand All @@ -91,7 +91,7 @@ impl HasherPrivateImpl of HasherPrivateTrait {
if num_bytes != 8 {
assert!(
value / one_shift_left_bytes_u64(num_bytes) == 0,
"Hasher::push_num_bytes: value is too large"
"Hasher::push_num_bytes: value is too large",
);
}
let num_high_bytes = min(num_bytes, 8 - self.num_last_bytes);
Expand All @@ -107,14 +107,14 @@ impl HasherPrivateImpl of HasherPrivateTrait {
if num_bytes != 8 {
assert!(
value / one_shift_left_bytes_u64(num_bytes) == 0,
"Hasher::push_to_last: value is too large"
"Hasher::push_to_last: value is too large",
);
}
if num_bytes == 8 {
self.last_be = value;
} else {
self.last_be = self.last_be * one_shift_left_bytes_u64(num_bytes) + value;
};
}
self.num_last_bytes += num_bytes;
if self.num_last_bytes == 8 {
self.inputs_le.append(u64_byte_reverse(self.last_be));
Expand Down
18 changes: 9 additions & 9 deletions target_chains/starknet/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pub mod pyth;
pub mod wormhole;
pub mod byte_buffer;
pub mod reader;
pub mod hash;
pub mod util;
pub mod merkle_tree;
pub mod pyth;
pub mod reader;
pub mod util;
pub mod wormhole;

pub use byte_buffer::{ByteBuffer, ByteBufferTrait};
pub use pyth::{
Event, PriceFeedUpdated, WormholeAddressSet, GovernanceDataSourceSet, ContractUpgraded,
DataSourcesSet, FeeSet, GetPriceUnsafeError, GovernanceActionError, UpdatePriceFeedsError,
GetPriceNoOlderThanError, UpdatePriceFeedsIfNecessaryError, ParsePriceFeedsError, IPyth,
IPythDispatcher, IPythDispatcherTrait, DataSource, Price, PriceFeedPublishTime, PriceFeed,
ContractUpgraded, DataSource, DataSourcesSet, Event, FeeSet, GetPriceNoOlderThanError,
GetPriceUnsafeError, GovernanceActionError, GovernanceDataSourceSet, IPyth, IPythDispatcher,
IPythDispatcherTrait, ParsePriceFeedsError, Price, PriceFeed, PriceFeedPublishTime,
PriceFeedUpdated, UpdatePriceFeedsError, UpdatePriceFeedsIfNecessaryError, WormholeAddressSet,
};
pub use util::{exp10, UnwrapWithFelt252, ResultMapErrInto};
pub use util::{ResultMapErrInto, UnwrapWithFelt252, exp10};
8 changes: 4 additions & 4 deletions target_chains/starknet/contracts/src/merkle_tree.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::hash::{Hasher, HasherImpl};
use core::cmp::{max, min};
use core::panic_with_felt252;
use super::hash::HasherImpl;
use super::reader::{Reader, ReaderImpl};
use super::byte_buffer::ByteBuffer;
use super::util::ONE_SHIFT_96;
use core::cmp::{min, max};
use core::panic_with_felt252;

const MERKLE_LEAF_PREFIX: u8 = 0;
const MERKLE_NODE_PREFIX: u8 = 1;
Expand Down Expand Up @@ -60,7 +60,7 @@ pub fn read_and_verify_proof(root_digest: u256, message: @ByteBuffer, ref reader
let sibling_digest = reader.read_u160();
current_hash = node_hash(current_hash, sibling_digest);
i += 1;
};
}

if root_digest != current_hash {
panic_with_felt252(MerkleVerificationError::DigestMismatch.into());
Expand Down
Loading
Loading