Skip to content

Commit

Permalink
Merge branch 'macOs-Build' into cairo-1
Browse files Browse the repository at this point in the history
  • Loading branch information
remollemo authored Jan 16, 2025
2 parents f55793c + c787ec8 commit f45ec3a
Show file tree
Hide file tree
Showing 57 changed files with 1,003 additions and 931 deletions.
12 changes: 11 additions & 1 deletion cairo_project.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
[crate_roots]
starkgate = "cairo"
src = "src/cairo"
openzeppelin = "src/openzeppelin"

[config.global]
edition = "2023_01"

[config.global.dependencies.openzeppelin]
discriminator = "openzeppelin"

[config.global.dependencies.src]
discriminator = "src"
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ black==23.1a1
cairo-lang==0.11.2
web3==5.31.3
pytest==7.4.4
sympy==1.12
14 changes: 7 additions & 7 deletions scripts/build-cairo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ pushd $(dirname $0)/..
set -e
mkdir -p cairo_contracts

scripts/starknet-compile.py src --contract-path src::strk::erc20_lockable::ERC20Lockable cairo_contracts/ERC20Lockable.sierra
scripts/starknet-compile.py src --contract-path src::update_712_vars_eic::Update712VarsEIC cairo_contracts/Update712VarsEIC.sierra
scripts/starknet-compile.py src --contract-path src::roles_init_eic::RolesExternalInitializer cairo_contracts/RolesExternalInitializer.sierra
scripts/starknet-compile.py src --contract-path src::legacy_bridge_eic::LegacyBridgeUpgradeEIC cairo_contracts/LegacyBridgeUpgradeEIC.sierra
scripts/starknet-compile.py src --contract-path src::token_bridge::TokenBridge cairo_contracts/TokenBridge.sierra
scripts/starknet-compile.py src --contract-path openzeppelin::token::erc20::presets::erc20_votes_lock::ERC20VotesLock cairo_contracts/ERC20VotesLock.sierra
scripts/starknet-compile.py src --contract-path openzeppelin::token::erc20_v070::erc20::ERC20 cairo_contracts/ERC20.sierra
scripts/starknet-compile.py src --contract-path src::strk::erc20_lockable::ERC20Lockable cairo_contracts/ERC20Lockable.sierra
scripts/starknet-compile.py src --contract-path src::update_712_vars_eic::Update712VarsEIC cairo_contracts/Update712VarsEIC.sierra
scripts/starknet-compile.py src --contract-path src::roles_init_eic::RolesExternalInitializer cairo_contracts/RolesExternalInitializer.sierra
scripts/starknet-compile.py src --contract-path src::legacy_bridge_eic::LegacyBridgeUpgradeEIC cairo_contracts/LegacyBridgeUpgradeEIC.sierra
scripts/starknet-compile.py src --contract-path src::token_bridge::TokenBridge cairo_contracts/TokenBridge.sierra
scripts/starknet-compile.py src --contract-path openzeppelin::token::erc20::presets::erc20_votes_lock::ERC20VotesLock cairo_contracts/ERC20VotesLock.sierra
scripts/starknet-compile.py src --contract-path openzeppelin::token::erc20_v070::erc20::ERC20 cairo_contracts/ERC20.sierra
set +e
popd
2 changes: 1 addition & 1 deletion scripts/cairo-format.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
EXECUTABLE = os.path.join(ROOT_DIR, ".downloads", "cairo", "bin", "cairo-format")
EXPECTED_EXECUTABLE_VERSION = "cairo-format 2.6.3"
EXPECTED_EXECUTABLE_VERSION = "cairo-format 2.10.0-rc.0"


def main():
Expand Down
2 changes: 1 addition & 1 deletion scripts/cairo-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
EXECUTABLE = os.path.join(ROOT_DIR, ".downloads", "cairo", "bin", "cairo-test")
EXPECTED_EXECUTABLE_VERSION = "cairo-test 2.6.3"
EXPECTED_EXECUTABLE_VERSION = "cairo-test 2.10.0-rc.0"


def main():
Expand Down
5 changes: 2 additions & 3 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ printf "${COLOR_OFF}"
mkdir -p .downloads
cd .downloads


if [ "$(uname)" == "Darwin" ]; then
# Do something under Mac OS X platform
wget -c https://github.com/starkware-libs/cairo/releases/download/v2.6.3/release-aarch64-apple-darwin.tar -O - | tar -xz
wget -c https://github.com/starkware-libs/cairo/releases/download/v2.10.0-rc.0/release-aarch64-apple-darwin.tar -O - | tar -xz
curl https://binaries.soliditylang.org/linux-amd64/solc-macos-amd64-v0.8.20+commit.a1b79de6 -o solc-0.8.20 && chmod +x solc-0.8.20
else
wget -c https://github.com/starkware-libs/cairo/releases/download/v2.6.3/release-x86_64-unknown-linux-musl.tar.gz -O - | tar -xz
wget -c https://github.com/starkware-libs/cairo/releases/download/v2.10.0-rc.0/release-x86_64-unknown-linux-musl.tar.gz -O - | tar -xz
curl https://binaries.soliditylang.org/linux-amd64/solc-linux-amd64-v0.8.20+commit.a1b79de6 -o solc-0.8.20 && chmod +x solc-0.8.20
fi

Expand Down
2 changes: 1 addition & 1 deletion scripts/starknet-compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

ROOT_DIR = os.path.dirname(os.path.dirname(__file__))
EXECUTABLE = os.path.join(ROOT_DIR, ".downloads", "cairo", "bin", "starknet-compile")
EXPECTED_EXECUTABLE_VERSION = "starknet-compile 2.6.3"
EXPECTED_EXECUTABLE_VERSION = "starknet-compile 2.10.0-rc.0"


def main():
Expand Down
8 changes: 4 additions & 4 deletions src/cairo/erc20_interface.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ trait IERC20<TContractState> {
fn allowance(self: @TContractState, owner: ContractAddress, spender: ContractAddress) -> u256;
fn transfer(ref self: TContractState, recipient: ContractAddress, amount: u256) -> bool;
fn transfer_from(
ref self: TContractState, sender: ContractAddress, recipient: ContractAddress, amount: u256
ref self: TContractState, sender: ContractAddress, recipient: ContractAddress, amount: u256,
) -> bool;
fn approve(ref self: TContractState, spender: ContractAddress, amount: u256) -> bool;
fn increase_allowance(
ref self: TContractState, spender: ContractAddress, added_value: u256
ref self: TContractState, spender: ContractAddress, added_value: u256,
) -> bool;
fn decrease_allowance(
ref self: TContractState, spender: ContractAddress, subtracted_value: u256
ref self: TContractState, spender: ContractAddress, subtracted_value: u256,
) -> bool;
}

Expand All @@ -26,7 +26,7 @@ trait IERC20CamelOnly<TState> {
fn totalSupply(self: @TState) -> u256;
fn balanceOf(self: @TState, account: ContractAddress) -> u256;
fn transferFrom(
ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256
ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256,
) -> bool;
}

16 changes: 8 additions & 8 deletions src/cairo/legacy_bridge_eic.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@
mod LegacyBridgeUpgradeEIC {
const WITHDRAWAL_LIMIT_PCT: u8 = 5;
use starknet::{
ContractAddress, get_caller_address, EthAddress, EthAddressIntoFelt252, EthAddressSerde
ContractAddress, get_caller_address, EthAddress, EthAddressIntoFelt252, EthAddressSerde,
};
use super::super::erc20_interface::{IERC20Dispatcher, IERC20DispatcherTrait};
use super::super::access_control_interface::{
IAccessControl, RoleId, RoleAdminChanged, RoleGranted
IAccessControl, RoleId, RoleAdminChanged, RoleGranted,
};
use super::super::replaceability_interface::IEICInitializable;
use super::super::roles_interface::{
APP_GOVERNOR, APP_ROLE_ADMIN, GOVERNANCE_ADMIN, OPERATOR, SECURITY_ADMIN, SECURITY_AGENT,
TOKEN_ADMIN, UPGRADE_GOVERNOR
TOKEN_ADMIN, UPGRADE_GOVERNOR,
};

#[storage]
struct Storage {
// --- Token Bridge ---
// Mapping from between l1<->l2 token addresses.
l1_l2_token_map: LegacyMap<EthAddress, ContractAddress>,
l2_l1_token_map: LegacyMap<ContractAddress, EthAddress>,
l1_l2_token_map: starknet::storage::Map<EthAddress, ContractAddress>,
l2_l1_token_map: starknet::storage::Map<ContractAddress, EthAddress>,
daily_withdrawal_limit_pct: u8,
// `l2_token` is a legacy storage variable from older versions.
// It's expected to be non-empty only in a case of an upgrade from such a version.
// This case also implies that this is the only token that is served by the bridge.
l2_token: ContractAddress,
// --- Access Control ---
// For each role id store its role admin id.
role_admin: LegacyMap<RoleId, RoleId>,
role_admin: starknet::storage::Map<RoleId, RoleId>,
// For each role and address, stores true if the address has this role; otherwise, false.
role_members: LegacyMap<(RoleId, ContractAddress), bool>,
role_members: starknet::storage::Map<(RoleId, ContractAddress), bool>,
}

#[derive(Copy, Drop, PartialEq, starknet::Event)]
Expand Down Expand Up @@ -99,7 +99,7 @@ mod LegacyBridgeUpgradeEIC {
}

fn setup_l1_l2_mappings(
ref self: ContractState, l1_token: EthAddress, l2_token: ContractAddress
ref self: ContractState, l1_token: EthAddress, l2_token: ContractAddress,
) {
// Check that running on legacy bridge context.
let legacy_l2_token = self.l2_token.read();
Expand Down
20 changes: 10 additions & 10 deletions src/cairo/legacy_bridge_tester.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod LegacyBridgeTester {
use starknet::{ContractAddress, syscalls::library_call_syscall, get_block_timestamp};
use super::super::replaceability_interface::{
ImplementationData, IReplaceable, IReplaceableDispatcher, IReplaceableDispatcherTrait,
IEICInitializable, EIC_INITIALIZE_SELECTOR, IMPLEMENTATION_EXPIRATION
IEICInitializable, EIC_INITIALIZE_SELECTOR, IMPLEMENTATION_EXPIRATION,
};

#[storage]
Expand All @@ -19,9 +19,9 @@ mod LegacyBridgeTester {
// Delay in seconds before performing an upgrade.
upgrade_delay: u64,
// Timestamp by which implementation can be activated.
impl_activation_time: LegacyMap<felt252, u64>,
impl_activation_time: starknet::storage::Map<felt252, u64>,
// Timestamp until which implementation can be activated.
impl_expiration_time: LegacyMap<felt252, u64>,
impl_expiration_time: starknet::storage::Map<felt252, u64>,
// Is the implementation finalized.
finalized: bool,
}
Expand Down Expand Up @@ -49,15 +49,15 @@ mod LegacyBridgeTester {

// Returns the implementation activation time.
fn get_impl_activation_time(
self: @ContractState, implementation_data: ImplementationData
self: @ContractState, implementation_data: ImplementationData,
) -> u64 {
let impl_key = calc_impl_key(:implementation_data);
self.impl_activation_time.read(impl_key)
}

// Adds a new implementation.
fn add_new_implementation(
ref self: ContractState, implementation_data: ImplementationData
ref self: ContractState, implementation_data: ImplementationData,
) {
// The call is restricted to the upgrade governor.
self.only_upgrade_governor();
Expand Down Expand Up @@ -119,7 +119,7 @@ mod LegacyBridgeTester {
let mut res = library_call_syscall(
class_hash: eic_data.eic_hash,
function_selector: EIC_INITIALIZE_SELECTOR,
calldata: calldata_wrapper.span()
calldata: calldata_wrapper.span(),
);
if (!res.is_ok()) {
let mut err = res.unwrap_err();
Expand All @@ -128,7 +128,7 @@ mod LegacyBridgeTester {
assert(false, err_msg);
}
},
Option::None(()) => {}
Option::None(()) => {},
};

// Replace the class hash.
Expand All @@ -155,21 +155,21 @@ mod LegacyBridgeTester {


fn set_impl_activation_time(
ref self: ContractState, implementation_data: ImplementationData, activation_time: u64
ref self: ContractState, implementation_data: ImplementationData, activation_time: u64,
) {
let impl_key = calc_impl_key(:implementation_data);
self.impl_activation_time.write(impl_key, activation_time);
}

fn get_impl_expiration_time(
self: @ContractState, implementation_data: ImplementationData
self: @ContractState, implementation_data: ImplementationData,
) -> u64 {
let impl_key = calc_impl_key(:implementation_data);
self.impl_expiration_time.read(impl_key)
}

fn set_impl_expiration_time(
ref self: ContractState, implementation_data: ImplementationData, expiration_time: u64
ref self: ContractState, implementation_data: ImplementationData, expiration_time: u64,
) {
let impl_key = calc_impl_key(:implementation_data);
self.impl_expiration_time.write(impl_key, expiration_time);
Expand Down
Loading

0 comments on commit f45ec3a

Please sign in to comment.