Skip to content

Commit

Permalink
upgraded to cairo 2.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ametel01 committed Aug 9, 2024
1 parent 9e0780b commit a7b0fc1
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 59 deletions.
2 changes: 1 addition & 1 deletion starknet/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
starknet-foundry 0.27.0
scarb 2.6.5
scarb 2.7.0
starkli 0.3.3
3 changes: 2 additions & 1 deletion starknet/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ edition = "2023_11"

[dependencies]
starknet = "2.6.3"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.13.0" }
openzeppelin_access = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0" }
openzeppelin_upgrades = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.15.0" }

[dev-dependencies]
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.27.0" }
Expand Down
31 changes: 16 additions & 15 deletions starknet/src/L1_headers_store/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ pub mod L1HeaderStore {
use fossil::library::words64_utils::words64_to_u256;
use fossil::types::ProcessBlockOptions;
use fossil::types::Words64Sequence;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin_access::ownable::OwnableComponent;
use starknet::storage::Map;
// *************************************************************************
// IMPORTS
// *************************************************************************
// Core lib imports
use openzeppelin::access::ownable::ownable::OwnableComponent::InternalTrait;
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::upgrades::interface::IUpgradeable;
use openzeppelin_access::ownable::ownable::OwnableComponent::InternalTrait;
use openzeppelin_upgrades::UpgradeableComponent;
use openzeppelin_upgrades::interface::IUpgradeable;
use starknet::{ContractAddress, EthAddress, get_caller_address, ClassHash};

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
Expand All @@ -51,16 +52,16 @@ pub mod L1HeaderStore {
starknet_handler_address: ContractAddress,
l1_messages_origin: ContractAddress,
latest_l1_block: u64,
block_parent_hash: LegacyMap::<u64, u256>,
block_state_root: LegacyMap::<u64, u256>,
block_transactions_root: LegacyMap::<u64, u256>,
block_receipts_root: LegacyMap::<u64, u256>,
block_uncles_hash: LegacyMap::<u64, u256>,
block_beneficiary: LegacyMap::<u64, EthAddress>,
block_difficulty: LegacyMap::<u64, u64>,
block_base_fee: LegacyMap::<u64, u64>,
block_timestamp: LegacyMap::<u64, u64>,
block_gas_used: LegacyMap::<u64, u64>,
block_parent_hash: Map<u64, u256>,
block_state_root: Map<u64, u256>,
block_transactions_root: Map<u64, u256>,
block_receipts_root: Map<u64, u256>,
block_uncles_hash: Map<u64, u256>,
block_beneficiary: Map<u64, EthAddress>,
block_difficulty: Map<u64, u64>,
block_base_fee: Map<u64, u64>,
block_timestamp: Map<u64, u64>,
block_gas_used: Map<u64, u64>,
}

// *************************************************************************
Expand Down Expand Up @@ -198,7 +199,7 @@ pub mod L1HeaderStore {
/// This may only be called by the contract owner.
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradeable._upgrade(new_class_hash);
self.upgradeable.upgrade(new_class_hash);
}
}

Expand Down
8 changes: 4 additions & 4 deletions starknet/src/L1_messages_proxy/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub mod L1MessagesProxy {
};
use fossil::L1_messages_proxy::interface::IL1MessagesProxy;
use fossil::library::words64_utils::words64_to_u256;
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::upgrades::interface::IUpgradeable;
use openzeppelin_access::ownable::OwnableComponent;
use openzeppelin_upgrades::UpgradeableComponent;
use openzeppelin_upgrades::interface::IUpgradeable;
// *************************************************************************
// IMPORTS
// *************************************************************************
Expand Down Expand Up @@ -166,7 +166,7 @@ pub mod L1MessagesProxy {
/// This may only be called by the contract owner.
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradeable._upgrade(new_class_hash);
self.upgradeable.upgrade(new_class_hash);
}
}
}
21 changes: 11 additions & 10 deletions starknet/src/fact_registry/contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ pub mod FactRegistry {
rlp_utils::{to_rlp_array, extract_data, extract_element}, keccak_utils::keccak_words64
};
use fossil::types::{Words64Sequence, RLPItem};
use openzeppelin::access::ownable::OwnableComponent;
use openzeppelin::upgrades::UpgradeableComponent;
use openzeppelin::upgrades::interface::IUpgradeable;
use openzeppelin_access::ownable::OwnableComponent;
use openzeppelin_upgrades::UpgradeableComponent;
use openzeppelin_upgrades::interface::IUpgradeable;
// Core lib imports
use starknet::{ContractAddress, EthAddress, contract_address_const, ClassHash};
use starknet::storage::Map;

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: UpgradeableComponent, storage: upgradeable, event: upgradeableEvent);
Expand All @@ -48,12 +49,12 @@ pub mod FactRegistry {
#[substorage(v0)]
upgradeable: UpgradeableComponent::Storage,
l1_headers_store: IL1HeadersStoreDispatcher,
verified_account: LegacyMap::<(EthAddress, u64), bool>,
verified_account_storage_hash: LegacyMap::<(EthAddress, u64), u256>,
verified_account_code_hash: LegacyMap::<(EthAddress, u64), u256>,
verified_account_balance: LegacyMap::<(EthAddress, u64), u256>,
verified_account_nonce: LegacyMap::<(EthAddress, u64), u64>,
verified_storage: LegacyMap::<(EthAddress, u64, u256), (bool, u256)>,
verified_account: Map<(EthAddress, u64), bool>,
verified_account_storage_hash: Map<(EthAddress, u64), u256>,
verified_account_code_hash: Map<(EthAddress, u64), u256>,
verified_account_balance: Map<(EthAddress, u64), u256>,
verified_account_nonce: Map<(EthAddress, u64), u64>,
verified_storage: Map<(EthAddress, u64, u256), (bool, u256)>,
}
// *************************************************************************
// EVENTS
Expand Down Expand Up @@ -293,7 +294,7 @@ pub mod FactRegistry {
/// This may only be called by the contract owner.
fn upgrade(ref self: ContractState, new_class_hash: ClassHash) {
self.ownable.assert_only_owner();
self.upgradeable._upgrade(new_class_hash);
self.upgradeable.upgrade(new_class_hash);
}
}

Expand Down
9 changes: 0 additions & 9 deletions starknet/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ pub mod library {
pub mod words64_utils;
}

#[cfg(test)]
pub mod testing {
pub mod rlp;
pub mod proofs {
pub mod account;
pub mod blocks;
pub mod storage;
}
}
22 changes: 9 additions & 13 deletions starknet/src/library/bitshift.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
// The following code was taken from the Alexandria library and added as internal library to
// make auditing easier. The original code can be found at https://github.com/keep-starknet-strange/alexandria/blob/main/src/math/src/lib.cairo

use core::integer::{
BoundedInt, u8_wide_mul, u16_wide_mul, u32_wide_mul, u64_wide_mul, u128_wide_mul,
u256_overflow_mul
};
use core::num::traits::{Bounded, OverflowingMul,WideMul};
use fossil::library::math_utils::pow;

pub trait BitShift<T> {
Expand All @@ -14,7 +10,7 @@ pub trait BitShift<T> {

pub impl U8BitShift of BitShift<u8> {
fn shl(x: u8, n: u8) -> u8 {
(u8_wide_mul(x, pow(2, n)) & BoundedInt::<u8>::max().into()).try_into().unwrap()
(WideMul::wide_mul(x, pow(2, n)) & Bounded::<u8>::MAX.into()).try_into().unwrap()
}

fn shr(x: u8, n: u8) -> u8 {
Expand All @@ -24,7 +20,7 @@ pub impl U8BitShift of BitShift<u8> {

pub impl U16BitShift of BitShift<u16> {
fn shl(x: u16, n: u16) -> u16 {
(u16_wide_mul(x, pow(2, n)) & BoundedInt::<u16>::max().into()).try_into().unwrap()
(WideMul::wide_mul(x, pow(2, n)) & Bounded::<u16>::MAX.into()).try_into().unwrap()
}

fn shr(x: u16, n: u16) -> u16 {
Expand All @@ -34,7 +30,7 @@ pub impl U16BitShift of BitShift<u16> {

pub impl U32BitShift of BitShift<u32> {
fn shl(x: u32, n: u32) -> u32 {
(u32_wide_mul(x, pow(2, n)) & BoundedInt::<u32>::max().into()).try_into().unwrap()
(WideMul::wide_mul(x, pow(2, n)) & Bounded::<u32>::MAX.into()).try_into().unwrap()
}

fn shr(x: u32, n: u32) -> u32 {
Expand All @@ -44,7 +40,7 @@ pub impl U32BitShift of BitShift<u32> {

pub impl U64BitShift of BitShift<u64> {
fn shl(x: u64, n: u64) -> u64 {
(u64_wide_mul(x, pow(2, n)) & BoundedInt::<u64>::max().into()).try_into().unwrap()
(WideMul::wide_mul(x, pow(2, n)) & Bounded::<u64>::MAX.into()).try_into().unwrap()
}

fn shr(x: u64, n: u64) -> u64 {
Expand All @@ -54,8 +50,8 @@ pub impl U64BitShift of BitShift<u64> {

pub impl U128BitShift of BitShift<u128> {
fn shl(x: u128, n: u128) -> u128 {
let (_, bottom_word) = u128_wide_mul(x, pow(2, n));
bottom_word
let res = WideMul::wide_mul(x, pow(2, n));
res.low
}

fn shr(x: u128, n: u128) -> u128 {
Expand All @@ -65,8 +61,8 @@ pub impl U128BitShift of BitShift<u128> {

pub impl U256BitShift of BitShift<u256> {
fn shl(x: u256, n: u256) -> u256 {
let (r, _) = u256_overflow_mul(x, pow(2, n));
r
let res = WideMul::wide_mul(x, pow(2, n));
u256{low: res.limb0, high: res.limb1}
}

fn shr(x: u256, n: u256) -> u256 {
Expand Down
12 changes: 12 additions & 0 deletions starknet/tests/lib.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod test_fact_registry;
mod test_l1_headers_store;
mod test_l1_messages_proxy;
pub mod utils {
pub mod rlp;
pub mod proofs {
pub mod account;
pub mod blocks;
pub mod storage;
}
pub mod test_utils;
}
4 changes: 2 additions & 2 deletions starknet/tests/test_fact_registry.cairo
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use fossil::library::words64_utils::Words64Trait;
use fossil::testing::proofs;
use super::utils::proofs;
use fossil::{
L1_headers_store::interface::IL1HeadersStoreDispatcherTrait,
fact_registry::interface::IFactRegistryDispatcherTrait
};
use snforge_std::start_cheat_caller_address;
use super::test_utils::{setup, OWNER, STARKNET_HANDLER};
use super::utils::test_utils::{setup, OWNER, STARKNET_HANDLER};

#[test]
fn prove_all_test_success_mainnet_weth() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use fossil::L1_headers_store::interface::IL1HeadersStoreDispatcherTrait;
use fossil::library::words64_utils::{words64_to_nibbles, Words64Trait};
use fossil::testing::proofs;
use fossil::testing::rlp;
use super::utils::{proofs, rlp};
use fossil::types::ProcessBlockOptions;
use snforge_std::start_cheat_caller_address;
use starknet::EthAddress;
use super::test_utils::{setup, OWNER, STARKNET_HANDLER};
use super::utils::test_utils::{setup, OWNER, STARKNET_HANDLER};

#[test]
fn receive_from_l1_success_test() {
Expand Down
2 changes: 1 addition & 1 deletion starknet/tests/test_l1_messages_proxy.cairo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use fossil::L1_messages_proxy::interface::IL1MessagesProxyDispatcherTrait;
use snforge_std::start_cheat_caller_address;
use starknet::EthAddress;
use super::test_utils::{setup, OWNER, L1_ORIGIN, STARKNET_HANDLER};
use super::utils::test_utils::{setup, OWNER, L1_ORIGIN, STARKNET_HANDLER};

#[test]
fn set_l1_headers_store_test_success() {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit a7b0fc1

Please sign in to comment.