From 4ea8e5d7d53891edd8c6cef6836dab33e2aabedc Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Wed, 30 Oct 2024 18:14:31 +0100 Subject: [PATCH 1/9] WIP --- cairo/kakarot-ssj/crates/contracts/Scarb.toml | 4 +- .../crates/contracts/src/lib.cairo | 4 + .../crates/contracts/src/test_utils.cairo | 21 +++- .../crates/contracts/src/token/erc20.cairo | 104 ++++++++++++++++++ 4 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo diff --git a/cairo/kakarot-ssj/crates/contracts/Scarb.toml b/cairo/kakarot-ssj/crates/contracts/Scarb.toml index 1e689c03e..e43eff8b8 100644 --- a/cairo/kakarot-ssj/crates/contracts/Scarb.toml +++ b/cairo/kakarot-ssj/crates/contracts/Scarb.toml @@ -8,8 +8,8 @@ edition = "2024_07" [dependencies] starknet.workspace = true evm = { path = "../evm" } -openzeppelin = { path = "../openzeppelin" } utils = { path = "../utils" } +openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag="v0.16.0" } [tool] fmt.workspace = true @@ -17,7 +17,7 @@ fmt.workspace = true [[target.starknet-contract]] casm = true casm-add-pythonic-hints = true -build-external-contracts = ["openzeppelin::token::erc20::erc20::ERC20"] +# build-external-contracts = ["openzeppelin::token::erc20::erc20::ERC20"] [lib] name = "contracts" diff --git a/cairo/kakarot-ssj/crates/contracts/src/lib.cairo b/cairo/kakarot-ssj/crates/contracts/src/lib.cairo index 995015b10..5c1001224 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/lib.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/lib.cairo @@ -35,3 +35,7 @@ pub mod test_contracts { pub mod mocks { pub mod cairo1_helpers_fixture; } + +pub mod token { + pub mod erc20; +} diff --git a/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo b/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo index e56908366..ec2bc1225 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo @@ -42,9 +42,24 @@ pub mod constants { } pub fn deploy_native_token() -> IERC20CamelDispatcher { - let calldata: Array = array![ - 'STARKNET_ETH', 'ETH', 0x00, 0xfffffffffffffffffffffffffff, constants::ETH_BANK().into() - ]; + // let calldata: Array = array![ + // 'STARKNET_ETH', 'ETH', 0x00, 0xfffffffffffffffffffffffffff, constants::ETH_BANK().into() + // ]; + let name: ByteArray = "STARKNET_ETH"; + let symbol: ByteArray = "ETH"; + // let initial_supply: u256 = 0xfffffffffffffffffffffffffff; + let initial_supply: u256 = u256 { high: 0x00, low: 0xfffffffffffffffffffffffffff }; + + let mut calldata = array![]; + // calldata.append_serde(name); + // calldata.append_serde(symbol); + // calldata.append_serde(initial_supply); + // calldata.append_serde(constants::ETH_BANK().into()); + name.serialize(ref calldata); + symbol.serialize(ref calldata); + initial_supply.serialize(ref calldata); + constants::ETH_BANK().serialize(ref calldata); + let class = declare("ERC20").unwrap().contract_class().class_hash; let maybe_address = deploy_syscall(*class, 0, calldata.span(), false); match maybe_address { diff --git a/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo b/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo new file mode 100644 index 000000000..6abb4a8fc --- /dev/null +++ b/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo @@ -0,0 +1,104 @@ +#[starknet::contract] +pub mod ERC20 { + use openzeppelin::introspection::src5::SRC5Component; + use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; + use starknet::{ContractAddress, get_caller_address}; + + component!(path: ERC20Component, storage: erc20, event: ERC20Event); + component!(path: SRC5Component, storage: src5, event: SRC5Event); + + #[abi(embed_v0)] + impl ERC20Impl = ERC20Component::ERC20Impl; + #[abi(embed_v0)] + impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; + #[abi(embed_v0)] + impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; + + impl ERC20InternalImpl = ERC20Component::InternalImpl; + + #[abi(embed_v0)] + impl SRC5Impl = SRC5Component::SRC5Impl; + impl SRC5InternalImpl = SRC5Component::InternalImpl; + + #[storage] + struct Storage { + #[substorage(v0)] + erc20: ERC20Component::Storage, + #[substorage(v0)] + src5: SRC5Component::Storage, + } + + #[event] + #[derive(Drop, starknet::Event)] + enum Event { + #[flat] + ERC20Event: ERC20Component::Event, + #[flat] + SRC5Event: SRC5Component::Event, + } + + #[constructor] + fn constructor( + ref self: ContractState, + name: ByteArray, + symbol: ByteArray, + initial_supply: u256, + recipient: ContractAddress + ) { + self.erc20.initializer(name, symbol); + self.erc20.mint(recipient, initial_supply); + } + + + #[abi(embed_v0)] + fn increase_allowance( + ref self: ContractState, spender: ContractAddress, added_value: u256 + ) -> bool { + self._increase_allowance(spender, added_value) + } + + + #[abi(embed_v0)] + fn increaseAllowance( + ref self: ContractState, spender: ContractAddress, addedValue: u256 + ) -> bool { + increase_allowance(ref self, spender, addedValue) + } + + + #[abi(embed_v0)] + fn decrease_allowance( + ref self: ContractState, spender: ContractAddress, subtracted_value: u256 + ) -> bool { + self._decrease_allowance(spender, subtracted_value) + } + + + #[abi(embed_v0)] + fn decreaseAllowance( + ref self: ContractState, spender: ContractAddress, subtractedValue: u256 + ) -> bool { + decrease_allowance(ref self, spender, subtractedValue) + } + + + #[generate_trait] + impl PrivateImpl of PrivateTrait { + fn _increase_allowance( + ref self: ContractState, spender: ContractAddress, added_value: u256 + ) -> bool { + let caller = get_caller_address(); + self.erc20._approve(caller, spender, self.erc20.allowance(caller, spender) + added_value); + true + } + + fn _decrease_allowance( + ref self: ContractState, spender: ContractAddress, subtracted_value: u256 + ) -> bool { + let caller = get_caller_address(); + self.erc20._approve( + caller, spender, self.erc20.allowance(caller, spender) - subtracted_value + ); + true + } +}} From e2733adcadab8a4f613754ee8fbdf997a79b62e7 Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Wed, 30 Oct 2024 22:43:33 +0100 Subject: [PATCH 2/9] fix test --- .../crates/contracts/src/test_utils.cairo | 23 +++++++------------ .../crates/contracts/src/token/erc20.cairo | 19 +++++++++------ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo b/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo index ec2bc1225..c20f8f8bc 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo @@ -1,3 +1,4 @@ +use core::num::traits::Bounded; use core::result::ResultTrait; use core::starknet::syscalls::deploy_syscall; use core::starknet::{EthAddress, ContractAddress}; @@ -42,23 +43,15 @@ pub mod constants { } pub fn deploy_native_token() -> IERC20CamelDispatcher { - // let calldata: Array = array![ - // 'STARKNET_ETH', 'ETH', 0x00, 0xfffffffffffffffffffffffffff, constants::ETH_BANK().into() - // ]; let name: ByteArray = "STARKNET_ETH"; let symbol: ByteArray = "ETH"; - // let initial_supply: u256 = 0xfffffffffffffffffffffffffff; - let initial_supply: u256 = u256 { high: 0x00, low: 0xfffffffffffffffffffffffffff }; - - let mut calldata = array![]; - // calldata.append_serde(name); - // calldata.append_serde(symbol); - // calldata.append_serde(initial_supply); - // calldata.append_serde(constants::ETH_BANK().into()); - name.serialize(ref calldata); - symbol.serialize(ref calldata); - initial_supply.serialize(ref calldata); - constants::ETH_BANK().serialize(ref calldata); + let initial_supply = Bounded::::MAX; + + let mut calldata = array![]; + name.serialize(ref calldata); + symbol.serialize(ref calldata); + initial_supply.serialize(ref calldata); + constants::ETH_BANK().serialize(ref calldata); let class = declare("ERC20").unwrap().contract_class().class_hash; let maybe_address = deploy_syscall(*class, 0, calldata.span(), false); diff --git a/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo b/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo index 6abb4a8fc..84dda0802 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo @@ -6,16 +6,16 @@ pub mod ERC20 { component!(path: ERC20Component, storage: erc20, event: ERC20Event); component!(path: SRC5Component, storage: src5, event: SRC5Event); - + #[abi(embed_v0)] impl ERC20Impl = ERC20Component::ERC20Impl; #[abi(embed_v0)] impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; #[abi(embed_v0)] impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; - + impl ERC20InternalImpl = ERC20Component::InternalImpl; - + #[abi(embed_v0)] impl SRC5Impl = SRC5Component::SRC5Impl; impl SRC5InternalImpl = SRC5Component::InternalImpl; @@ -84,11 +84,13 @@ pub mod ERC20 { #[generate_trait] impl PrivateImpl of PrivateTrait { - fn _increase_allowance( + fn _increase_allowance( ref self: ContractState, spender: ContractAddress, added_value: u256 ) -> bool { let caller = get_caller_address(); - self.erc20._approve(caller, spender, self.erc20.allowance(caller, spender) + added_value); + self + .erc20 + ._approve(caller, spender, self.erc20.allowance(caller, spender) + added_value); true } @@ -96,9 +98,12 @@ pub mod ERC20 { ref self: ContractState, spender: ContractAddress, subtracted_value: u256 ) -> bool { let caller = get_caller_address(); - self.erc20._approve( + self + .erc20 + ._approve( caller, spender, self.erc20.allowance(caller, spender) - subtracted_value ); true + } } -}} +} From af0c799d66cf337ca96a018841fe514103696654 Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Wed, 30 Oct 2024 23:26:19 +0100 Subject: [PATCH 3/9] use OZ's ownable component --- cairo/kakarot-ssj/Scarb.lock | 88 +++++- .../contracts/src/account_contract.cairo | 18 +- .../crates/contracts/src/components.cairo | 3 +- .../contracts/src/components/ownable.cairo | 91 ------ .../contracts/src/kakarot_core/kakarot.cairo | 16 +- .../contracts/src/uninitialized_account.cairo | 17 +- .../crates/contracts/tests/test_ownable.cairo | 210 -------------- cairo/kakarot-ssj/crates/evm/Scarb.toml | 2 +- .../crates/openzeppelin/Scarb.toml | 32 --- .../crates/openzeppelin/src/lib.cairo | 1 - .../crates/openzeppelin/src/token.cairo | 1 - .../crates/openzeppelin/src/token/erc20.cairo | 6 - .../openzeppelin/src/token/erc20/erc20.cairo | 259 ------------------ .../src/token/erc20/interface.cairo | 90 ------ 14 files changed, 118 insertions(+), 716 deletions(-) delete mode 100644 cairo/kakarot-ssj/crates/contracts/src/components/ownable.cairo delete mode 100644 cairo/kakarot-ssj/crates/contracts/tests/test_ownable.cairo delete mode 100644 cairo/kakarot-ssj/crates/openzeppelin/Scarb.toml delete mode 100644 cairo/kakarot-ssj/crates/openzeppelin/src/lib.cairo delete mode 100644 cairo/kakarot-ssj/crates/openzeppelin/src/token.cairo delete mode 100644 cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20.cairo delete mode 100644 cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/erc20.cairo delete mode 100644 cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/interface.cairo diff --git a/cairo/kakarot-ssj/Scarb.lock b/cairo/kakarot-ssj/Scarb.lock index 8a345708d..a02913e7f 100644 --- a/cairo/kakarot-ssj/Scarb.lock +++ b/cairo/kakarot-ssj/Scarb.lock @@ -38,11 +38,95 @@ source = "git+https://github.com/keep-starknet-strange/garaga.git#933784eee38113 [[package]] name = "openzeppelin" -version = "0.1.0" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" dependencies = [ - "snforge_std", + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_governance", + "openzeppelin_introspection", + "openzeppelin_merkle_tree", + "openzeppelin_presets", + "openzeppelin_security", + "openzeppelin_token", + "openzeppelin_upgrades", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_access" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +dependencies = [ + "openzeppelin_introspection", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_account" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +dependencies = [ + "openzeppelin_introspection", + "openzeppelin_utils", +] + +[[package]] +name = "openzeppelin_governance" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +dependencies = [ + "openzeppelin_access", + "openzeppelin_introspection", +] + +[[package]] +name = "openzeppelin_introspection" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" + +[[package]] +name = "openzeppelin_merkle_tree" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" + +[[package]] +name = "openzeppelin_presets" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +dependencies = [ + "openzeppelin_access", + "openzeppelin_account", + "openzeppelin_introspection", + "openzeppelin_token", + "openzeppelin_upgrades", +] + +[[package]] +name = "openzeppelin_security" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" + +[[package]] +name = "openzeppelin_token" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +dependencies = [ + "openzeppelin_account", + "openzeppelin_governance", + "openzeppelin_introspection", ] +[[package]] +name = "openzeppelin_upgrades" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" + +[[package]] +name = "openzeppelin_utils" +version = "0.16.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" + [[package]] name = "snforge_scarb_plugin" version = "0.31.0" diff --git a/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo b/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo index 5de99dd12..1c2ad1f05 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo @@ -59,9 +59,7 @@ pub mod AccountContract { use core::starknet::{ EthAddress, ClassHash, get_caller_address, get_tx_info, get_block_timestamp }; - use crate::components::ownable::IOwnable; - use crate::components::ownable::ownable_component::InternalTrait; - use crate::components::ownable::ownable_component; + use openzeppelin::access::ownable::OwnableComponent; use crate::errors::KAKAROT_REENTRANCY; use crate::kakarot_core::eth_rpc::{IEthRPCDispatcher, IEthRPCDispatcherTrait}; use crate::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait}; @@ -73,10 +71,13 @@ pub mod AccountContract { use utils::traits::DefaultSignature; // Add ownable component - component!(path: ownable_component, storage: ownable, event: OwnableEvent); + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] - impl OwnableImpl = ownable_component::Ownable; - impl OwnableInternal = ownable_component::InternalImpl; + impl OwnableImpl = OwnableComponent::OwnableImpl; + #[abi(embed_v0)] + impl OwnableCamelOnlyImpl = + OwnableComponent::OwnableCamelOnlyImpl; + impl InternalImplOwnable = OwnableComponent::InternalImpl; const VERSION: u32 = 000_001_000; @@ -93,14 +94,15 @@ pub mod AccountContract { pub(crate) Account_evm_address: EthAddress, pub(crate) Account_code_hash: u256, #[substorage(v0)] - ownable: ownable_component::Storage + ownable: OwnableComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] pub enum Event { transaction_executed: TransactionExecuted, - OwnableEvent: ownable_component::Event + #[flat] + OwnableEvent: OwnableComponent::Event, } #[derive(Drop, starknet::Event, Debug)] diff --git a/cairo/kakarot-ssj/crates/contracts/src/components.cairo b/cairo/kakarot-ssj/crates/contracts/src/components.cairo index 5ba62d80e..58f8b510f 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/components.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/components.cairo @@ -1,2 +1 @@ -pub mod ownable; -pub mod upgradeable; +pub mod upgradeable; \ No newline at end of file diff --git a/cairo/kakarot-ssj/crates/contracts/src/components/ownable.cairo b/cairo/kakarot-ssj/crates/contracts/src/components/ownable.cairo deleted file mode 100644 index fc8f88db7..000000000 --- a/cairo/kakarot-ssj/crates/contracts/src/components/ownable.cairo +++ /dev/null @@ -1,91 +0,0 @@ -// This implementation of an Ownable is inspired by Openzeppelin's work on -// OpenZeppelin Contracts for Cairo available here: https://github.com/OpenZeppelin/cairo-contracts - -use core::starknet::ContractAddress; -pub mod Errors { - pub const NOT_OWNER: felt252 = 'Caller is not the owner'; - pub const ZERO_ADDRESS_CALLER: felt252 = 'Caller is the zero address'; - pub const ZERO_ADDRESS_OWNER: felt252 = 'New owner is the zero address'; -} - -#[starknet::interface] -pub trait IOwnable { - fn owner(self: @TContractState) -> ContractAddress; - fn transfer_ownership(ref self: TContractState, new_owner: ContractAddress); - fn renounce_ownership(ref self: TContractState); -} - -#[starknet::component] -pub mod ownable_component { - use core::num::traits::Zero; - use core::starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess}; - use core::starknet::{get_caller_address, ContractAddress}; - use super::Errors; - - #[storage] - pub struct Storage { - pub Ownable_owner: ContractAddress - } - - #[event] - #[derive(Drop, starknet::Event)] - pub enum Event { - OwnershipTransferred: OwnershipTransferred - } - - #[derive(Drop, starknet::Event)] - pub struct OwnershipTransferred { - pub previous_owner: ContractAddress, - pub new_owner: ContractAddress, - } - - - #[embeddable_as(Ownable)] - pub impl OwnableImpl< - TContractState, +HasComponent - > of super::IOwnable> { - fn owner(self: @ComponentState) -> ContractAddress { - self.Ownable_owner.read() - } - - fn transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress - ) { - assert(!new_owner.is_zero(), Errors::ZERO_ADDRESS_OWNER); - self.assert_only_owner(); - self._transfer_ownership(new_owner); - } - - fn renounce_ownership(ref self: ComponentState) { - self.assert_only_owner(); - self._transfer_ownership(Zero::zero()); - } - } - - #[generate_trait] - pub impl InternalImpl< - TContractState, +HasComponent - > of InternalTrait { - fn initializer(ref self: ComponentState, owner: ContractAddress) { - self._transfer_ownership(owner); - } - - fn assert_only_owner(self: @ComponentState) { - let owner: ContractAddress = self.Ownable_owner.read(); - let caller: ContractAddress = get_caller_address(); - assert(!caller.is_zero(), Errors::ZERO_ADDRESS_CALLER); - assert(caller == owner, Errors::NOT_OWNER); - } - - fn _transfer_ownership( - ref self: ComponentState, new_owner: ContractAddress - ) { - let previous_owner: ContractAddress = self.Ownable_owner.read(); - self.Ownable_owner.write(new_owner); - self - .emit( - OwnershipTransferred { previous_owner: previous_owner, new_owner: new_owner } - ); - } - } -} diff --git a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo index 2b5f14355..942bf9cc3 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo @@ -11,7 +11,7 @@ pub mod KakarotCore { StoragePointerWriteAccess }; use core::starknet::{EthAddress, ContractAddress, ClassHash, get_contract_address}; - use crate::components::ownable::{ownable_component}; + use openzeppelin::access::ownable::OwnableComponent; use crate::components::upgradeable::{IUpgradeable, upgradeable_component}; use crate::kakarot_core::eth_rpc; use crate::kakarot_core::interface::IKakarotCore; @@ -19,7 +19,7 @@ pub mod KakarotCore { use evm::model::account::AccountTrait; use utils::helpers::compute_starknet_address; - component!(path: ownable_component, storage: ownable, event: OwnableEvent); + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent); /// STORAGE /// @@ -36,7 +36,7 @@ pub mod KakarotCore { pub Kakarot_block_gas_limit: u64, // Components #[substorage(v0)] - ownable: ownable_component::Storage, + ownable: OwnableComponent::Storage, #[substorage(v0)] upgradeable: upgradeable_component::Storage, } @@ -46,7 +46,8 @@ pub mod KakarotCore { #[event] #[derive(Drop, starknet::Event)] pub enum Event { - OwnableEvent: ownable_component::Event, + #[flat] + OwnableEvent: OwnableComponent::Event, UpgradeableEvent: upgradeable_component::Event, AccountDeployed: AccountDeployed, AccountClassHashChange: AccountClassHashChange, @@ -114,7 +115,10 @@ pub mod KakarotCore { // Public-facing "ownable" functions #[abi(embed_v0)] - impl OwnableImpl = ownable_component::Ownable; + impl OwnableImpl = OwnableComponent::OwnableImpl; + #[abi(embed_v0)] + impl OwnableCamelOnlyImpl = + OwnableComponent::OwnableCamelOnlyImpl; /// Public-facing "ethereum" functions /// Used to make EVM-related actions through Kakarot. @@ -211,7 +215,7 @@ pub mod KakarotCore { /// INTERNAL-FACING FUNCTIONS /// // Internal-facing "ownable" functions - impl OwnableInternalImpl = ownable_component::InternalImpl; + impl InternalImplOwnable = OwnableComponent::InternalImpl; // Internal-facing "upgradeable" functions impl UpgradeableImpl = upgradeable_component::Upgradeable; diff --git a/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo b/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo index 46c4ea9e0..0be5c8a71 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo @@ -22,26 +22,29 @@ pub mod UninitializedAccount { use core::starknet::SyscallResultTrait; use core::starknet::syscalls::{library_call_syscall, replace_class_syscall}; use core::starknet::{ContractAddress, get_caller_address}; - use crate::components::ownable::ownable_component::InternalTrait; - use crate::components::ownable::ownable_component; + use openzeppelin::access::ownable::OwnableComponent; use crate::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait}; // Add ownable component - component!(path: ownable_component, storage: ownable, event: OwnableEvent); + component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] - impl OwnableImpl = ownable_component::Ownable; - impl OwnableInternal = ownable_component::InternalImpl; + impl OwnableImpl = OwnableComponent::OwnableImpl; + #[abi(embed_v0)] + impl OwnableCamelOnlyImpl = + OwnableComponent::OwnableCamelOnlyImpl; + impl InternalImplOwnable = OwnableComponent::InternalImpl; #[storage] struct Storage { #[substorage(v0)] - ownable: ownable_component::Storage, + ownable: OwnableComponent::Storage, } #[event] #[derive(Drop, starknet::Event)] enum Event { - OwnableEvent: ownable_component::Event + #[flat] + OwnableEvent: OwnableComponent::Event, } #[constructor] diff --git a/cairo/kakarot-ssj/crates/contracts/tests/test_ownable.cairo b/cairo/kakarot-ssj/crates/contracts/tests/test_ownable.cairo deleted file mode 100644 index d5ac7ca2a..000000000 --- a/cairo/kakarot-ssj/crates/contracts/tests/test_ownable.cairo +++ /dev/null @@ -1,210 +0,0 @@ -use contracts::components::ownable::{ownable_component}; -use contracts::test_utils::constants::{ZERO, OWNER, OTHER}; -use core::num::traits::Zero; -use core::starknet::ContractAddress; - - -use ownable_component::{InternalImpl, OwnableImpl}; -use snforge_std::{start_cheat_caller_address, spy_events, test_address, EventSpyTrait}; -use snforge_utils::snforge_utils::{EventsFilterBuilderTrait, ContractEventsTrait}; - - -#[starknet::contract] -pub mod MockContract { - use contracts::components::ownable::{ownable_component}; - - component!(path: ownable_component, storage: ownable, event: OwnableEvent); - - #[abi(embed_v0)] - impl OwnableImpl = ownable_component::Ownable; - - impl OwnableInternalImpl = ownable_component::InternalImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - ownable: ownable_component::Storage - } - - - #[event] - #[derive(Drop, starknet::Event)] - pub enum Event { - OwnableEvent: ownable_component::Event - } -} -type TestingState = ownable_component::ComponentState; - -impl TestingStateDefault of Default { - fn default() -> TestingState { - ownable_component::component_state_for_testing() - } -} - -#[generate_trait] -impl TestingStateImpl of TestingStateTrait { - fn new_with(owner: ContractAddress) -> TestingState { - let mut ownable: TestingState = Default::default(); - ownable.initializer(owner); - ownable - } -} - -#[test] -fn test_ownable_initializer() { - let mut ownable: TestingState = Default::default(); - let test_address: ContractAddress = test_address(); - assert(ownable.owner().is_zero(), 'owner should be zero'); - - let mut spy = spy_events(); - ownable.initializer(OWNER()); - let expected = MockContract::Event::OwnableEvent( - ownable_component::Event::OwnershipTransferred( - ownable_component::OwnershipTransferred { previous_owner: ZERO(), new_owner: OWNER() } - ) - ); - let contract_events = EventsFilterBuilderTrait::from_events(@spy.get_events()) - .with_contract_address(test_address) - .build(); - contract_events.assert_emitted(@expected); - assert(ownable.owner() == OWNER(), 'Owner should be set'); -} - -#[test] -fn test_assert_only_owner() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - start_cheat_caller_address(test_address, OWNER()); - - ownable.assert_only_owner(); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_assert_only_owner_not_owner() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - start_cheat_caller_address(test_address, OTHER()); - - ownable.assert_only_owner(); -} - -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_assert_only_owner_zero() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - start_cheat_caller_address(test_address, ZERO()); - ownable.assert_only_owner(); -} - -#[test] -fn test__transfer_ownership() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - - let mut spy = spy_events(); - let expected = MockContract::Event::OwnableEvent( - ownable_component::Event::OwnershipTransferred( - ownable_component::OwnershipTransferred { previous_owner: OWNER(), new_owner: OTHER() } - ) - ); - ownable._transfer_ownership(OTHER()); - - let contract_events = EventsFilterBuilderTrait::from_events(@spy.get_events()) - .with_contract_address(test_address) - .build(); - contract_events.assert_emitted(@expected); - assert(ownable.owner() == OTHER(), 'Owner should be OTHER'); -} - - -#[test] -fn test_transfer_ownership() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - start_cheat_caller_address(test_address, OWNER()); - - let mut spy = spy_events(); - ownable.transfer_ownership(OTHER()); - let expected = MockContract::Event::OwnableEvent( - ownable_component::Event::OwnershipTransferred( - ownable_component::OwnershipTransferred { previous_owner: OWNER(), new_owner: OTHER() } - ) - ); - let contract_events = EventsFilterBuilderTrait::from_events(@spy.get_events()) - .with_contract_address(test_address) - .build(); - contract_events.assert_emitted(@expected); - - assert(ownable.owner() == OTHER(), 'Should transfer ownership'); -} - -#[test] -#[should_panic(expected: ('New owner is the zero address',))] -fn test_transfer_ownership_to_zero() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - start_cheat_caller_address(test_address, OWNER()); - - ownable.transfer_ownership(ZERO()); -} - - -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_transfer_ownership_from_zero() { - let mut ownable: TestingState = Default::default(); - - ownable.transfer_ownership(OTHER()); -} - - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_transfer_ownership_from_nonowner() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - start_cheat_caller_address(test_address, OTHER()); - - ownable.transfer_ownership(OTHER()); -} - - -#[test] -fn test_renounce_ownership() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - - start_cheat_caller_address(test_address, OWNER()); - let mut spy = spy_events(); - ownable.renounce_ownership(); - let expected = MockContract::Event::OwnableEvent( - ownable_component::Event::OwnershipTransferred( - ownable_component::OwnershipTransferred { previous_owner: OWNER(), new_owner: ZERO() } - ) - ); - let contract_events = EventsFilterBuilderTrait::from_events(@spy.get_events()) - .with_contract_address(test_address) - .build(); - contract_events.assert_emitted(@expected); - - assert(ownable.owner().is_zero(), 'ownership not renounced'); -} - -#[test] -#[should_panic(expected: ('Caller is the zero address',))] -fn test_renounce_ownership_from_zero_address() { - let mut ownable: TestingState = Default::default(); - ownable.renounce_ownership(); -} - -#[test] -#[should_panic(expected: ('Caller is not the owner',))] -fn test_renounce_ownership_from_nonowner() { - let mut ownable: TestingState = TestingStateTrait::new_with(OWNER()); - let test_address: ContractAddress = test_address(); - start_cheat_caller_address(test_address, OTHER()); - - ownable.renounce_ownership(); -} diff --git a/cairo/kakarot-ssj/crates/evm/Scarb.toml b/cairo/kakarot-ssj/crates/evm/Scarb.toml index 1180c54a4..055e0c4e7 100644 --- a/cairo/kakarot-ssj/crates/evm/Scarb.toml +++ b/cairo/kakarot-ssj/crates/evm/Scarb.toml @@ -9,8 +9,8 @@ edition = "2024_07" starknet.workspace = true utils = { path = "../utils" } contracts = { path = "../contracts" } -openzeppelin = { path = "../openzeppelin" } garaga = { git = "https://github.com/keep-starknet-strange/garaga.git" } +openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag="v0.16.0" } [dev-dependencies] snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.31.0" } diff --git a/cairo/kakarot-ssj/crates/openzeppelin/Scarb.toml b/cairo/kakarot-ssj/crates/openzeppelin/Scarb.toml deleted file mode 100644 index 5b90de13d..000000000 --- a/cairo/kakarot-ssj/crates/openzeppelin/Scarb.toml +++ /dev/null @@ -1,32 +0,0 @@ -# Due to the following error, we have to manually copy paste contracts from Open Zeppelin -# error: Version solving failed: -# - openzeppelin v0.7.0 (git+https:#github.com/OpenZeppelin/cairo-contracts.git?tag=v0.7.0#61a2505fe0c0f19b5de2b3f8dedf421ba2cff657) cannot use starknet v2.3.0-rc0 (std), because openzeppelin requires starknet >=2.2.0 - -# Scarb does not have real version solving algorithm yet. -# Perhaps in the future this conflict could be resolved, but currently, -# please upgrade your dependencies to use latest versions of their dependencies. -# -# -# Credits: "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.7.0" - - -[package] -name = "openzeppelin" -version = "0.1.0" -edition = "2024_07" - -# See more keys and their definitions at https://docs.swmansion.com/scarb/docs/reference/manifest.html - -[dependencies] -starknet.workspace = true - -[tool] -fmt.workspace = true - -[dev-dependencies] -snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.31.0" } -assert_macros = "2.8.2" - -[scripts] -test = "snforge test --max-n-steps 4294967295" -test-profiling = "snforge test --max-n-steps 4294967295 --build-profile" diff --git a/cairo/kakarot-ssj/crates/openzeppelin/src/lib.cairo b/cairo/kakarot-ssj/crates/openzeppelin/src/lib.cairo deleted file mode 100644 index 79c66ba63..000000000 --- a/cairo/kakarot-ssj/crates/openzeppelin/src/lib.cairo +++ /dev/null @@ -1 +0,0 @@ -pub mod token; diff --git a/cairo/kakarot-ssj/crates/openzeppelin/src/token.cairo b/cairo/kakarot-ssj/crates/openzeppelin/src/token.cairo deleted file mode 100644 index 8f3777f6b..000000000 --- a/cairo/kakarot-ssj/crates/openzeppelin/src/token.cairo +++ /dev/null @@ -1 +0,0 @@ -pub mod erc20; diff --git a/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20.cairo b/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20.cairo deleted file mode 100644 index 6779800b1..000000000 --- a/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20.cairo +++ /dev/null @@ -1,6 +0,0 @@ -pub mod erc20; -pub mod interface; - -pub use erc20::ERC20; -pub use interface::ERC20ABIDispatcher; -pub use interface::ERC20ABIDispatcherTrait; diff --git a/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/erc20.cairo b/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/erc20.cairo deleted file mode 100644 index e5604d4ed..000000000 --- a/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/erc20.cairo +++ /dev/null @@ -1,259 +0,0 @@ -// We manually copy pasted contracts from Open Zeppelin -// We adapted it to 2.7.1 version of Cairo -// Credits: "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.7.0" - -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.7.0 (token/erc20/erc20.cairo) - -#[starknet::contract] -pub mod ERC20 { - use core::num::traits::Bounded; - use core::num::traits::Zero; - use core::starknet::ContractAddress; - use core::starknet::get_caller_address; - use core::starknet::storage::{ - Map, StorageMapWriteAccess, StorageMapReadAccess, StoragePointerReadAccess, - StoragePointerWriteAccess, - }; - use openzeppelin::token::erc20::interface::{IERC20, IERC20CamelOnly}; - - #[storage] - struct Storage { - _name: felt252, - _symbol: felt252, - _total_supply: u256, - _balances: Map, - _allowances: Map<(ContractAddress, ContractAddress), u256>, - } - - #[event] - #[derive(Drop, starknet::Event)] - enum Event { - Transfer: Transfer, - Approval: Approval, - } - - #[derive(Drop, starknet::Event)] - struct Transfer { - #[key] - from: ContractAddress, - #[key] - to: ContractAddress, - value: u256 - } - - #[derive(Drop, starknet::Event)] - struct Approval { - #[key] - owner: ContractAddress, - #[key] - spender: ContractAddress, - value: u256 - } - - mod Errors { - pub const APPROVE_FROM_ZERO: felt252 = 'ERC20: approve from 0'; - pub const APPROVE_TO_ZERO: felt252 = 'ERC20: approve to 0'; - pub const TRANSFER_FROM_ZERO: felt252 = 'ERC20: transfer from 0'; - pub const TRANSFER_TO_ZERO: felt252 = 'ERC20: transfer to 0'; - pub const BURN_FROM_ZERO: felt252 = 'ERC20: burn from 0'; - pub const MINT_TO_ZERO: felt252 = 'ERC20: mint to 0'; - } - - #[constructor] - fn constructor( - ref self: ContractState, - name: felt252, - symbol: felt252, - initial_supply: u256, - recipient: ContractAddress - ) { - self.initializer(name, symbol); - self._mint(recipient, initial_supply); - } - - // - // External - // - - #[abi(embed_v0)] - impl ERC20Impl of IERC20 { - fn name(self: @ContractState) -> felt252 { - self._name.read() - } - - fn symbol(self: @ContractState) -> felt252 { - self._symbol.read() - } - - fn decimals(self: @ContractState) -> u8 { - 18 - } - - fn total_supply(self: @ContractState) -> u256 { - self._total_supply.read() - } - - fn balance_of(self: @ContractState, account: ContractAddress) -> u256 { - self._balances.read(account) - } - - fn allowance( - self: @ContractState, owner: ContractAddress, spender: ContractAddress - ) -> u256 { - self._allowances.read((owner, spender)) - } - - fn transfer(ref self: ContractState, recipient: ContractAddress, amount: u256) -> bool { - let sender = get_caller_address(); - self._transfer(sender, recipient, amount); - true - } - - fn transfer_from( - ref self: ContractState, - sender: ContractAddress, - recipient: ContractAddress, - amount: u256 - ) -> bool { - let caller = get_caller_address(); - self._spend_allowance(sender, caller, amount); - self._transfer(sender, recipient, amount); - true - } - - fn approve(ref self: ContractState, spender: ContractAddress, amount: u256) -> bool { - let caller = get_caller_address(); - self._approve(caller, spender, amount); - true - } - } - - #[abi(embed_v0)] - impl ERC20CamelOnlyImpl of IERC20CamelOnly { - fn totalSupply(self: @ContractState) -> u256 { - ERC20Impl::total_supply(self) - } - - fn balanceOf(self: @ContractState, account: ContractAddress) -> u256 { - ERC20Impl::balance_of(self, account) - } - - fn transferFrom( - ref self: ContractState, - sender: ContractAddress, - recipient: ContractAddress, - amount: u256 - ) -> bool { - ERC20Impl::transfer_from(ref self, sender, recipient, amount) - } - } - - - #[abi(embed_v0)] - fn increase_allowance( - ref self: ContractState, spender: ContractAddress, added_value: u256 - ) -> bool { - self._increase_allowance(spender, added_value) - } - - - #[abi(embed_v0)] - fn increaseAllowance( - ref self: ContractState, spender: ContractAddress, addedValue: u256 - ) -> bool { - increase_allowance(ref self, spender, addedValue) - } - - - #[abi(embed_v0)] - fn decrease_allowance( - ref self: ContractState, spender: ContractAddress, subtracted_value: u256 - ) -> bool { - self._decrease_allowance(spender, subtracted_value) - } - - - #[abi(embed_v0)] - fn decreaseAllowance( - ref self: ContractState, spender: ContractAddress, subtractedValue: u256 - ) -> bool { - decrease_allowance(ref self, spender, subtractedValue) - } - - // - // Internal - // - - #[generate_trait] - impl InternalImpl of InternalTrait { - fn initializer(ref self: ContractState, name: felt252, symbol: felt252) { - self._name.write(name); - self._symbol.write(symbol); - } - - fn _increase_allowance( - ref self: ContractState, spender: ContractAddress, added_value: u256 - ) -> bool { - let caller = get_caller_address(); - self._approve(caller, spender, self._allowances.read((caller, spender)) + added_value); - true - } - - fn _decrease_allowance( - ref self: ContractState, spender: ContractAddress, subtracted_value: u256 - ) -> bool { - let caller = get_caller_address(); - self - ._approve( - caller, spender, self._allowances.read((caller, spender)) - subtracted_value - ); - true - } - - fn _mint(ref self: ContractState, recipient: ContractAddress, amount: u256) { - assert(!recipient.is_zero(), Errors::MINT_TO_ZERO); - self._total_supply.write(self._total_supply.read() + amount); - self._balances.write(recipient, self._balances.read(recipient) + amount); - self.emit(Transfer { from: Zero::zero(), to: recipient, value: amount }); - } - - fn _burn(ref self: ContractState, account: ContractAddress, amount: u256) { - assert(!account.is_zero(), Errors::BURN_FROM_ZERO); - self._total_supply.write(self._total_supply.read() - amount); - self._balances.write(account, self._balances.read(account) - amount); - self.emit(Transfer { from: account, to: Zero::zero(), value: amount }); - } - - fn _approve( - ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256 - ) { - assert(!owner.is_zero(), Errors::APPROVE_FROM_ZERO); - assert(!spender.is_zero(), Errors::APPROVE_TO_ZERO); - self._allowances.write((owner, spender), amount); - self.emit(Approval { owner, spender, value: amount }); - } - - fn _transfer( - ref self: ContractState, - sender: ContractAddress, - recipient: ContractAddress, - amount: u256 - ) { - assert(!sender.is_zero(), Errors::TRANSFER_FROM_ZERO); - assert(!recipient.is_zero(), Errors::TRANSFER_TO_ZERO); - self._balances.write(sender, self._balances.read(sender) - amount); - self._balances.write(recipient, self._balances.read(recipient) + amount); - self.emit(Transfer { from: sender, to: recipient, value: amount }); - } - - fn _spend_allowance( - ref self: ContractState, owner: ContractAddress, spender: ContractAddress, amount: u256 - ) { - let current_allowance = self._allowances.read((owner, spender)); - if current_allowance != Bounded::MAX { - self._approve(owner, spender, current_allowance - amount); - } - } - } -} diff --git a/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/interface.cairo b/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/interface.cairo deleted file mode 100644 index 02c8c4f95..000000000 --- a/cairo/kakarot-ssj/crates/openzeppelin/src/token/erc20/interface.cairo +++ /dev/null @@ -1,90 +0,0 @@ -// Due to the following error, we have to manually copy paste contracts from Open Zeppelin -// error: Version solving failed: -// - openzeppelin v0.7.0 -// (git+https://github.com/OpenZeppelin/cairo-contracts.git?tag=v0.7.0#61a2505fe0c0f19b5de2b3f8dedf421ba2cff657) -// cannot use starknet v2.3.0-rc0 (std), because openzeppelin requires starknet >=2.2.0 - -// Scarb does not have real version solving algorithm yet. -// Perhaps in the future this conflict could be resolved, but currently, -// please upgrade your dependencies to use latest versions of their dependencies. -// Credits: "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.7.0" - -// SPDX-License-Identifier: MIT -// OpenZeppelin Contracts for Cairo v0.7.0 (token/erc20/interface.cairo) - -use core::starknet::ContractAddress; - -#[starknet::interface] -pub trait IERC20 { - fn name(self: @TState) -> felt252; - fn symbol(self: @TState) -> felt252; - fn decimals(self: @TState) -> u8; - fn total_supply(self: @TState) -> u256; - fn balance_of(self: @TState, account: ContractAddress) -> u256; - fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; - fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; - fn transfer_from( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool; - fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; -} - -#[starknet::interface] -pub trait IERC20Camel { - fn name(self: @TState) -> felt252; - fn symbol(self: @TState) -> felt252; - fn decimals(self: @TState) -> u8; - fn totalSupply(self: @TState) -> u256; - fn balanceOf(self: @TState, account: ContractAddress) -> u256; - fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; - fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; - fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool; - fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; -} - -#[starknet::interface] -pub trait IERC20CamelOnly { - fn totalSupply(self: @TState) -> u256; - fn balanceOf(self: @TState, account: ContractAddress) -> u256; - fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool; -} - -#[starknet::interface] -pub trait ERC20ABI { - fn name(self: @TState) -> felt252; - fn symbol(self: @TState) -> felt252; - fn decimals(self: @TState) -> u8; - fn total_supply(self: @TState) -> u256; - fn balance_of(self: @TState, account: ContractAddress) -> u256; - fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; - fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; - fn transfer_from( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool; - fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; - fn increase_allowance(ref self: TState, spender: ContractAddress, added_value: u256) -> bool; - fn decrease_allowance( - ref self: TState, spender: ContractAddress, subtracted_value: u256 - ) -> bool; -} - -#[starknet::interface] -pub trait ERC20CamelABI { - fn name(self: @TState) -> felt252; - fn symbol(self: @TState) -> felt252; - fn decimals(self: @TState) -> u8; - fn totalSupply(self: @TState) -> u256; - fn balanceOf(self: @TState, account: ContractAddress) -> u256; - fn allowance(self: @TState, owner: ContractAddress, spender: ContractAddress) -> u256; - fn transfer(ref self: TState, recipient: ContractAddress, amount: u256) -> bool; - fn transferFrom( - ref self: TState, sender: ContractAddress, recipient: ContractAddress, amount: u256 - ) -> bool; - fn approve(ref self: TState, spender: ContractAddress, amount: u256) -> bool; - fn increaseAllowance(ref self: TState, spender: ContractAddress, addedValue: u256) -> bool; - fn decreaseAllowance(ref self: TState, spender: ContractAddress, subtractedValue: u256) -> bool; -} From f502c1da1842f7f783fdb026767b76a362900f65 Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Thu, 31 Oct 2024 09:20:39 +0100 Subject: [PATCH 4/9] use OZ's upgradable component --- .../contracts/src/account_contract.cairo | 2 +- .../crates/contracts/src/components.cairo | 1 - .../contracts/src/kakarot_core/kakarot.cairo | 16 ++-- .../crates/contracts/src/lib.cairo | 1 - .../src/test_contracts/test_upgradeable.cairo | 78 +++++++++++++++---- .../contracts/src/uninitialized_account.cairo | 2 +- .../crates/contracts/tests/lib.cairo | 2 - 7 files changed, 71 insertions(+), 31 deletions(-) delete mode 100644 cairo/kakarot-ssj/crates/contracts/src/components.cairo diff --git a/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo b/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo index 1c2ad1f05..aeda3f88c 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo @@ -59,11 +59,11 @@ pub mod AccountContract { use core::starknet::{ EthAddress, ClassHash, get_caller_address, get_tx_info, get_block_timestamp }; - use openzeppelin::access::ownable::OwnableComponent; use crate::errors::KAKAROT_REENTRANCY; use crate::kakarot_core::eth_rpc::{IEthRPCDispatcher, IEthRPCDispatcherTrait}; use crate::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait}; use crate::storage::StorageBytecode; + use openzeppelin::access::ownable::OwnableComponent; use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; use super::OutsideExecution; use utils::eth_transaction::transaction::TransactionTrait; diff --git a/cairo/kakarot-ssj/crates/contracts/src/components.cairo b/cairo/kakarot-ssj/crates/contracts/src/components.cairo deleted file mode 100644 index 58f8b510f..000000000 --- a/cairo/kakarot-ssj/crates/contracts/src/components.cairo +++ /dev/null @@ -1 +0,0 @@ -pub mod upgradeable; \ No newline at end of file diff --git a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo index 942bf9cc3..713dcee42 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo @@ -11,17 +11,16 @@ pub mod KakarotCore { StoragePointerWriteAccess }; use core::starknet::{EthAddress, ContractAddress, ClassHash, get_contract_address}; - use openzeppelin::access::ownable::OwnableComponent; - use crate::components::upgradeable::{IUpgradeable, upgradeable_component}; use crate::kakarot_core::eth_rpc; use crate::kakarot_core::interface::IKakarotCore; use evm::backend::starknet_backend; use evm::model::account::AccountTrait; + use openzeppelin::access::ownable::OwnableComponent; + use openzeppelin::upgrades::upgradeable::UpgradeableComponent; use utils::helpers::compute_starknet_address; component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); - component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent); - + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); /// STORAGE /// #[storage] @@ -38,7 +37,7 @@ pub mod KakarotCore { #[substorage(v0)] ownable: OwnableComponent::Storage, #[substorage(v0)] - upgradeable: upgradeable_component::Storage, + upgradeable: UpgradeableComponent::Storage, } /// EVENTS /// @@ -48,7 +47,8 @@ pub mod KakarotCore { pub enum Event { #[flat] OwnableEvent: OwnableComponent::Event, - UpgradeableEvent: upgradeable_component::Event, + #[flat] + UpgradeableEvent: UpgradeableComponent::Event, AccountDeployed: AccountDeployed, AccountClassHashChange: AccountClassHashChange, EOAClassHashChange: EOAClassHashChange, @@ -151,7 +151,7 @@ pub mod KakarotCore { fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { self.ownable.assert_only_owner(); - self.upgradeable.upgrade_contract(new_class_hash); + self.upgradeable.upgrade(new_class_hash); } fn get_account_contract_class_hash(self: @ContractState) -> ClassHash { @@ -218,5 +218,5 @@ pub mod KakarotCore { impl InternalImplOwnable = OwnableComponent::InternalImpl; // Internal-facing "upgradeable" functions - impl UpgradeableImpl = upgradeable_component::Upgradeable; + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; } diff --git a/cairo/kakarot-ssj/crates/contracts/src/lib.cairo b/cairo/kakarot-ssj/crates/contracts/src/lib.cairo index 5c1001224..9ec59673c 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/lib.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/lib.cairo @@ -1,6 +1,5 @@ pub mod account_contract; pub mod cairo1_helpers; -pub mod components; pub mod errors; diff --git a/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo b/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo index 22cf19587..ae34157db 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo @@ -1,7 +1,3 @@ -use crate::components::upgradeable::{upgradeable_component}; - -use upgradeable_component::{UpgradeableImpl}; - #[starknet::interface] pub trait IMockContractUpgradeable { fn version(self: @TContractState) -> felt252; @@ -9,23 +5,24 @@ pub trait IMockContractUpgradeable { #[starknet::contract] pub mod MockContractUpgradeableV0 { - use crate::components::upgradeable::{upgradeable_component}; + use openzeppelin::upgrades::interface::IUpgradeable; + use openzeppelin::upgrades::upgradeable::UpgradeableComponent; + use starknet::{ClassHash}; use super::IMockContractUpgradeable; - component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent); + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); - #[abi(embed_v0)] - impl UpgradeableImpl = upgradeable_component::Upgradeable; + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; #[storage] struct Storage { #[substorage(v0)] - upgradeable: upgradeable_component::Storage + upgradeable: UpgradeableComponent::Storage } #[event] #[derive(Drop, starknet::Event)] pub enum Event { - UpgradeableEvent: upgradeable_component::Event + UpgradeableEvent: UpgradeableComponent::Event, } #[abi(embed_v0)] @@ -34,24 +31,36 @@ pub mod MockContractUpgradeableV0 { 0 } } + + + #[abi(embed_v0)] + impl UpgradeableImpl of IUpgradeable { + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { + self.upgradeable.upgrade(new_class_hash); + } + } } #[starknet::contract] pub mod MockContractUpgradeableV1 { - use crate::components::upgradeable::{upgradeable_component}; + use openzeppelin::upgrades::interface::IUpgradeable; + use openzeppelin::upgrades::upgradeable::UpgradeableComponent; + use starknet::{ClassHash}; use super::IMockContractUpgradeable; - component!(path: upgradeable_component, storage: upgradeable, event: upgradeableEvent); + component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); + + impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; #[storage] struct Storage { #[substorage(v0)] - upgradeable: upgradeable_component::Storage + upgradeable: UpgradeableComponent::Storage } #[event] #[derive(Drop, starknet::Event)] pub enum Event { - upgradeableEvent: upgradeable_component::Event + UpgradeableEvent: UpgradeableComponent::Event, } #[abi(embed_v0)] @@ -60,12 +69,48 @@ pub mod MockContractUpgradeableV1 { 1 } } + + + #[abi(embed_v0)] + impl UpgradeableImpl of IUpgradeable { + fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { + self.upgradeable.upgrade(new_class_hash); + } + } } +// #[starknet::contract] +// pub mod MockContractUpgradeableV1 { +// use openzeppelin::upgrades::upgradeable::UpgradeableComponent; +// use super::IMockContractUpgradeable; +// component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); + +// impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; + +// #[storage] +// struct Storage { +// #[substorage(v0)] +// upgradeable: UpgradeableComponent::Storage +// } + +// #[event] +// #[derive(Drop, starknet::Event)] +// pub enum Event { +// upgradeableEvent: UpgradeableComponent::Event +// } + +// #[abi(embed_v0)] +// impl MockContractUpgradeableImpl of IMockContractUpgradeable { +// fn version(self: @ContractState) -> felt252 { +// 1 +// } +// } +// } + #[cfg(test)] mod tests { use core::starknet::syscalls::{deploy_syscall}; - use crate::components::upgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait}; + use openzeppelin::upgrades::interface::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait}; use snforge_std::{declare, DeclareResultTrait}; use starknet::{ClassHash}; use super::{IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait}; @@ -92,8 +137,7 @@ mod tests { .class_hash); let new_class_hash: ClassHash = mock_contract_upgradeable_v1_class_hash; - IUpgradeableDispatcher { contract_address: contract_address } - .upgrade_contract(new_class_hash); + IUpgradeableDispatcher { contract_address: contract_address }.upgrade(new_class_hash); let version = IMockContractUpgradeableDispatcher { contract_address: contract_address } .version(); diff --git a/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo b/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo index 0be5c8a71..86f2a27b7 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/uninitialized_account.cairo @@ -22,8 +22,8 @@ pub mod UninitializedAccount { use core::starknet::SyscallResultTrait; use core::starknet::syscalls::{library_call_syscall, replace_class_syscall}; use core::starknet::{ContractAddress, get_caller_address}; - use openzeppelin::access::ownable::OwnableComponent; use crate::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait}; + use openzeppelin::access::ownable::OwnableComponent; // Add ownable component component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); diff --git a/cairo/kakarot-ssj/crates/contracts/tests/lib.cairo b/cairo/kakarot-ssj/crates/contracts/tests/lib.cairo index df3d540ee..06c4428fe 100644 --- a/cairo/kakarot-ssj/crates/contracts/tests/lib.cairo +++ b/cairo/kakarot-ssj/crates/contracts/tests/lib.cairo @@ -4,5 +4,3 @@ mod test_cairo1_helpers; mod test_execution_from_outside; mod test_kakarot_core; - -mod test_ownable; From 2d6e06fda5cf855ffa532419c66e6c86e2614c7d Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Thu, 31 Oct 2024 10:03:52 +0100 Subject: [PATCH 5/9] remove commented code --- .../src/test_contracts/test_upgradeable.cairo | 28 ------------------- 1 file changed, 28 deletions(-) diff --git a/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo b/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo index ae34157db..6450e5e08 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo @@ -79,34 +79,6 @@ pub mod MockContractUpgradeableV1 { } } -// #[starknet::contract] -// pub mod MockContractUpgradeableV1 { -// use openzeppelin::upgrades::upgradeable::UpgradeableComponent; -// use super::IMockContractUpgradeable; -// component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); - -// impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; - -// #[storage] -// struct Storage { -// #[substorage(v0)] -// upgradeable: UpgradeableComponent::Storage -// } - -// #[event] -// #[derive(Drop, starknet::Event)] -// pub enum Event { -// upgradeableEvent: UpgradeableComponent::Event -// } - -// #[abi(embed_v0)] -// impl MockContractUpgradeableImpl of IMockContractUpgradeable { -// fn version(self: @ContractState) -> felt252 { -// 1 -// } -// } -// } - #[cfg(test)] mod tests { use core::starknet::syscalls::{deploy_syscall}; From 26b15902cc67893eac7e1e0ce4e580578a036127 Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Thu, 31 Oct 2024 14:03:16 +0100 Subject: [PATCH 6/9] fix --- cairo/kakarot-ssj/crates/contracts/Scarb.toml | 1 - .../crates/contracts/src/account_contract.cairo | 7 ++----- .../crates/contracts/src/kakarot_core/eth_rpc.cairo | 6 +++--- .../crates/contracts/src/kakarot_core/kakarot.cairo | 3 --- .../crates/contracts/src/test_utils.cairo | 10 +++++----- .../crates/contracts/src/token/erc20.cairo | 12 ------------ .../contracts/tests/test_account_contract.cairo | 6 +++--- .../tests/test_execution_from_outside.cairo | 4 ++-- .../crates/evm/src/backend/starknet_backend.cairo | 6 +++--- 9 files changed, 18 insertions(+), 37 deletions(-) diff --git a/cairo/kakarot-ssj/crates/contracts/Scarb.toml b/cairo/kakarot-ssj/crates/contracts/Scarb.toml index e43eff8b8..9a33710e8 100644 --- a/cairo/kakarot-ssj/crates/contracts/Scarb.toml +++ b/cairo/kakarot-ssj/crates/contracts/Scarb.toml @@ -17,7 +17,6 @@ fmt.workspace = true [[target.starknet-contract]] casm = true casm-add-pythonic-hints = true -# build-external-contracts = ["openzeppelin::token::erc20::erc20::ERC20"] [lib] name = "contracts" diff --git a/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo b/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo index aeda3f88c..bb909f532 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo @@ -64,7 +64,7 @@ pub mod AccountContract { use crate::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait}; use crate::storage::StorageBytecode; use openzeppelin::access::ownable::OwnableComponent; - use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; + use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use super::OutsideExecution; use utils::eth_transaction::transaction::TransactionTrait; use utils::serialization::{deserialize_signature, deserialize_bytes, serialize_bytes}; @@ -74,9 +74,6 @@ pub mod AccountContract { component!(path: OwnableComponent, storage: ownable, event: OwnableEvent); #[abi(embed_v0)] impl OwnableImpl = OwnableComponent::OwnableImpl; - #[abi(embed_v0)] - impl OwnableCamelOnlyImpl = - OwnableComponent::OwnableCamelOnlyImpl; impl InternalImplOwnable = OwnableComponent::InternalImpl; @@ -134,7 +131,7 @@ pub mod AccountContract { // To internally perform value transfer of the network's native // token (which conforms to the ERC20 standard), we need to give the // KakarotCore contract infinite allowance - IERC20CamelDispatcher { contract_address: native_token } + IERC20Dispatcher { contract_address: native_token } .approve(kakarot_address, Bounded::::MAX); kakarot.register_account(evm_address); diff --git a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/eth_rpc.cairo b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/eth_rpc.cairo index f25ddc966..4f7face96 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/eth_rpc.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/eth_rpc.cairo @@ -9,7 +9,7 @@ use evm::backend::validation::validate_eth_tx; use evm::model::account::AccountTrait; use evm::model::{TransactionResult, Address}; use evm::{EVMTrait}; -use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; +use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use utils::constants::MAX_SAFE_CHAIN_ID; use utils::eth_transaction::transaction::{Transaction, TransactionTrait}; @@ -113,8 +113,8 @@ pub impl EthRPC< let kakarot_state = KakarotState::get_state(); let starknet_address = kakarot_state.get_starknet_address(address); let native_token_address = kakarot_state.get_native_token(); - let native_token = IERC20CamelDispatcher { contract_address: native_token_address }; - native_token.balanceOf(starknet_address) + let native_token = IERC20Dispatcher { contract_address: native_token_address }; + native_token.balance_of(starknet_address) } fn eth_get_transaction_count(self: @TContractState, address: EthAddress) -> u64 { diff --git a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo index 713dcee42..c733d67bd 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo @@ -116,9 +116,6 @@ pub mod KakarotCore { // Public-facing "ownable" functions #[abi(embed_v0)] impl OwnableImpl = OwnableComponent::OwnableImpl; - #[abi(embed_v0)] - impl OwnableCamelOnlyImpl = - OwnableComponent::OwnableCamelOnlyImpl; /// Public-facing "ethereum" functions /// Used to make EVM-related actions through Kakarot. diff --git a/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo b/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo index c20f8f8bc..9bc0ccad0 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/test_utils.cairo @@ -9,7 +9,7 @@ use crate::kakarot_core::{ use evm::model::{Address}; use evm::test_utils::{other_starknet_address, sequencer_evm_address, chain_id}; -use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; +use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use snforge_std::start_cheat_chain_id_global; use snforge_std::{ declare, DeclareResultTrait, start_cheat_caller_address, start_cheat_sequencer_address_global, @@ -42,7 +42,7 @@ pub mod constants { } } -pub fn deploy_native_token() -> IERC20CamelDispatcher { +pub fn deploy_native_token() -> IERC20Dispatcher { let name: ByteArray = "STARKNET_ETH"; let symbol: ByteArray = "ETH"; let initial_supply = Bounded::::MAX; @@ -56,7 +56,7 @@ pub fn deploy_native_token() -> IERC20CamelDispatcher { let class = declare("ERC20").unwrap().contract_class().class_hash; let maybe_address = deploy_syscall(*class, 0, calldata.span(), false); match maybe_address { - Result::Ok((contract_address, _)) => { IERC20CamelDispatcher { contract_address } }, + Result::Ok((contract_address, _)) => { IERC20Dispatcher { contract_address } }, Result::Err(err) => panic(err) } } @@ -136,14 +136,14 @@ pub fn call_transaction( } pub fn fund_account_with_native_token( - contract_address: ContractAddress, native_token: IERC20CamelDispatcher, amount: u256, + contract_address: ContractAddress, native_token: IERC20Dispatcher, amount: u256, ) { start_cheat_caller_address(native_token.contract_address, constants::ETH_BANK()); native_token.transfer(contract_address, amount); stop_cheat_caller_address(native_token.contract_address); } -pub fn setup_contracts_for_testing() -> (IERC20CamelDispatcher, IExtendedKakarotCoreDispatcher) { +pub fn setup_contracts_for_testing() -> (IERC20Dispatcher, IExtendedKakarotCoreDispatcher) { let sequencer: EthAddress = sequencer_evm_address(); let native_token = deploy_native_token(); let kakarot_core = deploy_kakarot_core(native_token.contract_address, [sequencer].span()); diff --git a/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo b/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo index 84dda0802..07396d17a 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/token/erc20.cairo @@ -1,31 +1,21 @@ #[starknet::contract] pub mod ERC20 { - use openzeppelin::introspection::src5::SRC5Component; use openzeppelin::token::erc20::{ERC20Component, ERC20HooksEmptyImpl}; use starknet::{ContractAddress, get_caller_address}; component!(path: ERC20Component, storage: erc20, event: ERC20Event); - component!(path: SRC5Component, storage: src5, event: SRC5Event); #[abi(embed_v0)] impl ERC20Impl = ERC20Component::ERC20Impl; #[abi(embed_v0)] impl ERC20MetadataImpl = ERC20Component::ERC20MetadataImpl; - #[abi(embed_v0)] - impl ERC20CamelOnlyImpl = ERC20Component::ERC20CamelOnlyImpl; impl ERC20InternalImpl = ERC20Component::InternalImpl; - #[abi(embed_v0)] - impl SRC5Impl = SRC5Component::SRC5Impl; - impl SRC5InternalImpl = SRC5Component::InternalImpl; - #[storage] struct Storage { #[substorage(v0)] erc20: ERC20Component::Storage, - #[substorage(v0)] - src5: SRC5Component::Storage, } #[event] @@ -33,8 +23,6 @@ pub mod ERC20 { enum Event { #[flat] ERC20Event: ERC20Component::Event, - #[flat] - SRC5Event: SRC5Component::Event, } #[constructor] diff --git a/cairo/kakarot-ssj/crates/contracts/tests/test_account_contract.cairo b/cairo/kakarot-ssj/crates/contracts/tests/test_account_contract.cairo index 430a5501c..b005bf63f 100644 --- a/cairo/kakarot-ssj/crates/contracts/tests/test_account_contract.cairo +++ b/cairo/kakarot-ssj/crates/contracts/tests/test_account_contract.cairo @@ -7,7 +7,7 @@ use contracts::{IAccountDispatcher, IAccountDispatcherTrait}; use core::starknet::EthAddress; use core::starknet::account::{Call}; use evm::test_utils::{ca_address, eoa_address}; -use openzeppelin::token::erc20::interface::IERC20CamelDispatcherTrait; +use openzeppelin::token::erc20::interface::IERC20DispatcherTrait; use snforge_std::{start_cheat_caller_address, stop_cheat_caller_address}; #[test] @@ -94,7 +94,7 @@ fn test_ca_external_starknet_call_native_token() { let call = Call { to: native_token.contract_address, - selector: selector!("balanceOf"), + selector: selector!("balance_of"), calldata: array![ca_address.starknet.into()].span(), }; start_cheat_caller_address(ca_address.starknet, kakarot_core.contract_address); @@ -103,7 +103,7 @@ fn test_ca_external_starknet_call_native_token() { assert(success, 'execute_starknet_call failed'); assert(data.len() == 2, 'wrong return data length'); - let balance = native_token.balanceOf(ca_address.starknet); + let balance = native_token.balance_of(ca_address.starknet); assert((*data[0], *data[1]) == (balance.low.into(), balance.high.into()), 'wrong return data'); } diff --git a/cairo/kakarot-ssj/crates/contracts/tests/test_execution_from_outside.cairo b/cairo/kakarot-ssj/crates/contracts/tests/test_execution_from_outside.cairo index 568565968..b3df50122 100644 --- a/cairo/kakarot-ssj/crates/contracts/tests/test_execution_from_outside.cairo +++ b/cairo/kakarot-ssj/crates/contracts/tests/test_execution_from_outside.cairo @@ -15,7 +15,7 @@ use core::starknet::secp256_trait::Signature; use core::starknet::{ContractAddress, contract_address_const, EthAddress, Event}; use evm::test_utils::chain_id; use evm::test_utils::other_evm_address; -use openzeppelin::token::erc20::interface::IERC20CamelDispatcher; +use openzeppelin::token::erc20::interface::IERC20Dispatcher; use snforge_std::{ start_cheat_caller_address, stop_cheat_caller_address, start_cheat_transaction_hash, spy_events, EventSpyTrait, CheatSpan, cheat_caller_address, stop_cheat_block_timestamp, @@ -132,7 +132,7 @@ impl OutsideExecutionBuilderImpl of OutsideExecutionBuilderTrait { } } -fn set_up() -> (IExtendedKakarotCoreDispatcher, IAccountDispatcher, IERC20CamelDispatcher) { +fn set_up() -> (IExtendedKakarotCoreDispatcher, IAccountDispatcher, IERC20Dispatcher) { let (native_token, kakarot_core) = setup_contracts_for_testing(); // When we deploy the EOA, we use get_caller_address to get the address of the KakarotCore // contract and set the caller address to that. diff --git a/cairo/kakarot-ssj/crates/evm/src/backend/starknet_backend.cairo b/cairo/kakarot-ssj/crates/evm/src/backend/starknet_backend.cairo index 26237c045..8ee90fbd6 100644 --- a/cairo/kakarot-ssj/crates/evm/src/backend/starknet_backend.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/backend/starknet_backend.cairo @@ -11,7 +11,7 @@ use crate::errors::{ensure, EVMError}; use crate::model::{Address, AddressTrait, Environment, Account, AccountTrait}; use crate::model::{Transfer}; use crate::state::{State, StateTrait}; -use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait}; +use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait}; use utils::constants::BURN_ADDRESS; use utils::constants; use utils::set::SetTrait; @@ -206,8 +206,8 @@ fn transfer_native_token(ref self: State) -> Result<(), EVMError> { let kakarot_state = KakarotCore::unsafe_new_contract_state(); let native_token = kakarot_state.get_native_token(); while let Option::Some(transfer) = self.transfers.pop_front() { - IERC20CamelDispatcher { contract_address: native_token } - .transferFrom(transfer.sender.starknet, transfer.recipient.starknet, transfer.amount); + IERC20Dispatcher { contract_address: native_token } + .transfer_from(transfer.sender.starknet, transfer.recipient.starknet, transfer.amount); }; Result::Ok(()) } From 83720e6e31164168cfbbe357c94f68caec7c5c27 Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Thu, 31 Oct 2024 14:46:21 +0100 Subject: [PATCH 7/9] - remove erc20 camelCase impl - refac: transition to snake_case --- .../src/components/upgradeable.cairo | 40 ------------------- .../crates/contracts/src/lib.cairo | 6 +-- .../mock_contract_upgradeable.cairo} | 38 ------------------ .../contracts/tests/test_kakarot_core.cairo | 2 +- .../crates/evm/src/backend/validation.cairo | 4 +- .../src/instructions/memory_operations.cairo | 6 +-- .../src/instructions/system_operations.cairo | 6 +-- .../crates/evm/src/model/account.cairo | 18 ++++----- .../crates/evm/src/precompiles/blake2f.cairo | 2 +- .../evm/src/precompiles/ec_recover.cairo | 2 +- .../crates/evm/src/precompiles/identity.cairo | 2 +- .../evm/src/precompiles/p256verify.cairo | 4 +- .../crates/evm/src/precompiles/sha256.cairo | 2 +- cairo/kakarot-ssj/crates/evm/src/state.cairo | 8 ++-- 14 files changed, 29 insertions(+), 111 deletions(-) delete mode 100644 cairo/kakarot-ssj/crates/contracts/src/components/upgradeable.cairo rename cairo/kakarot-ssj/crates/contracts/src/{test_contracts/test_upgradeable.cairo => mocks/mock_contract_upgradeable.cairo} (61%) diff --git a/cairo/kakarot-ssj/crates/contracts/src/components/upgradeable.cairo b/cairo/kakarot-ssj/crates/contracts/src/components/upgradeable.cairo deleted file mode 100644 index 67c441ef5..000000000 --- a/cairo/kakarot-ssj/crates/contracts/src/components/upgradeable.cairo +++ /dev/null @@ -1,40 +0,0 @@ -use core::starknet::ClassHash; - -#[starknet::interface] -pub trait IUpgradeable { - fn upgrade_contract(ref self: TContractState, new_class_hash: ClassHash); -} - - -#[starknet::component] -pub mod upgradeable_component { - use core::starknet::ClassHash; - use core::starknet::syscalls::{replace_class_syscall}; - - - #[storage] - pub struct Storage {} - - #[event] - #[derive(Drop, starknet::Event)] - pub enum Event { - ContractUpgraded: ContractUpgraded - } - - #[derive(Drop, starknet::Event)] - struct ContractUpgraded { - new_class_hash: ClassHash - } - - #[embeddable_as(Upgradeable)] - pub impl UpgradeableImpl< - TContractState, +HasComponent - > of super::IUpgradeable> { - fn upgrade_contract( - ref self: ComponentState, new_class_hash: starknet::ClassHash - ) { - replace_class_syscall(new_class_hash).expect('replace class failed'); - self.emit(ContractUpgraded { new_class_hash: new_class_hash }); - } - } -} diff --git a/cairo/kakarot-ssj/crates/contracts/src/lib.cairo b/cairo/kakarot-ssj/crates/contracts/src/lib.cairo index 9ec59673c..54da5e992 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/lib.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/lib.cairo @@ -26,13 +26,9 @@ pub use kakarot_core::{ }; pub use uninitialized_account::{UninitializedAccount}; -//TODO: hide this behind a feature flag -pub mod test_contracts { - pub mod test_upgradeable; -} - pub mod mocks { pub mod cairo1_helpers_fixture; + pub mod mock_contract_upgradeable; } pub mod token { diff --git a/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo b/cairo/kakarot-ssj/crates/contracts/src/mocks/mock_contract_upgradeable.cairo similarity index 61% rename from cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo rename to cairo/kakarot-ssj/crates/contracts/src/mocks/mock_contract_upgradeable.cairo index 6450e5e08..f94fd9365 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/test_contracts/test_upgradeable.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/mocks/mock_contract_upgradeable.cairo @@ -78,41 +78,3 @@ pub mod MockContractUpgradeableV1 { } } } - -#[cfg(test)] -mod tests { - use core::starknet::syscalls::{deploy_syscall}; - use openzeppelin::upgrades::interface::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait}; - use snforge_std::{declare, DeclareResultTrait}; - use starknet::{ClassHash}; - use super::{IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait}; - - #[test] - fn test_upgradeable_update_contract() { - let mock_contract_upgradeable_v0_class_hash = (*declare("MockContractUpgradeableV0") - .unwrap() - .contract_class() - .class_hash); - let (contract_address, _) = deploy_syscall( - mock_contract_upgradeable_v0_class_hash, 0, [].span(), false - ) - .unwrap(); - - let version = IMockContractUpgradeableDispatcher { contract_address: contract_address } - .version(); - - assert(version == 0, 'version is not 0'); - - let mock_contract_upgradeable_v1_class_hash = (*declare("MockContractUpgradeableV1") - .unwrap() - .contract_class() - .class_hash); - let new_class_hash: ClassHash = mock_contract_upgradeable_v1_class_hash; - - IUpgradeableDispatcher { contract_address: contract_address }.upgrade(new_class_hash); - - let version = IMockContractUpgradeableDispatcher { contract_address: contract_address } - .version(); - assert(version == 1, 'version is not 1'); - } -} diff --git a/cairo/kakarot-ssj/crates/contracts/tests/test_kakarot_core.cairo b/cairo/kakarot-ssj/crates/contracts/tests/test_kakarot_core.cairo index 2fbcedc30..faf745df7 100644 --- a/cairo/kakarot-ssj/crates/contracts/tests/test_kakarot_core.cairo +++ b/cairo/kakarot-ssj/crates/contracts/tests/test_kakarot_core.cairo @@ -1,7 +1,7 @@ use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait}; use contracts::kakarot_core::interface::IExtendedKakarotCoreDispatcherTrait; use contracts::kakarot_core::{KakarotCore}; -use contracts::test_contracts::test_upgradeable::{ +use contracts::mocks::mock_contract_upgradeable::{ IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait }; use contracts::test_data::{deploy_counter_calldata, counter_evm_bytecode}; diff --git a/cairo/kakarot-ssj/crates/evm/src/backend/validation.cairo b/cairo/kakarot-ssj/crates/evm/src/backend/validation.cairo index 30414f5ed..a857c84dc 100644 --- a/cairo/kakarot-ssj/crates/evm/src/backend/validation.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/backend/validation.cairo @@ -112,7 +112,7 @@ mod tests { account_starknet_address, selector!("get_evm_address"), account_evm_address ); start_mock_call( - native_token_address, selector!("balanceOf"), Bounded::::MAX + native_token_address, selector!("balance_of"), Bounded::::MAX ); // Min to pay for gas + value (kakarot_state, native_token_address) @@ -265,7 +265,7 @@ mod tests { } ); - start_mock_call(native_token_address, selector!("balanceOf"), Bounded::::MIN); + start_mock_call(native_token_address, selector!("balance_of"), Bounded::::MIN); // Test that the function performs validation and assert expected results validate_eth_tx(@kakarot_state, tx); diff --git a/cairo/kakarot-ssj/crates/evm/src/instructions/memory_operations.cairo b/cairo/kakarot-ssj/crates/evm/src/instructions/memory_operations.cairo index 4386d275b..a015d084b 100644 --- a/cairo/kakarot-ssj/crates/evm/src/instructions/memory_operations.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/instructions/memory_operations.cairo @@ -865,7 +865,7 @@ mod tests { vm.stack.push(key).expect('push failed'); // When - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); let result = vm.exec_sstore(); // Then @@ -924,7 +924,7 @@ mod tests { // When start_mock_call::(vm.message().target.starknet, selector!("storage"), 0); - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); let result = vm.exec_sstore(); // Then @@ -949,7 +949,7 @@ mod tests { // When start_mock_call::(starknet_address, selector!("storage"), 0); - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); let result = vm.exec_sstore(); // Then diff --git a/cairo/kakarot-ssj/crates/evm/src/instructions/system_operations.cairo b/cairo/kakarot-ssj/crates/evm/src/instructions/system_operations.cairo index 65b95d75d..3486fdae2 100644 --- a/cairo/kakarot-ssj/crates/evm/src/instructions/system_operations.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/instructions/system_operations.cairo @@ -889,7 +889,7 @@ mod tests { vm.stack.push(0).expect('push failed'); // When - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_create().unwrap(); EVMTrait::execute_code(ref vm); @@ -958,7 +958,7 @@ mod tests { vm.stack.push(1).expect('push failed'); // When - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_create().expect('exec_create failed'); EVMTrait::execute_code(ref vm); @@ -1026,7 +1026,7 @@ mod tests { vm.stack.push(0).expect('push failed'); // When - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_create2().unwrap(); EVMTrait::execute_code(ref vm); diff --git a/cairo/kakarot-ssj/crates/evm/src/model/account.cairo b/cairo/kakarot-ssj/crates/evm/src/model/account.cairo index 849afc84e..4fecd0a8c 100644 --- a/cairo/kakarot-ssj/crates/evm/src/model/account.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/model/account.cairo @@ -380,7 +380,7 @@ mod tests { }; // When - start_mock_call::(native_token(), selector!("balanceOf"), 100); + start_mock_call::(native_token(), selector!("balance_of"), 100); start_mock_call::(starknet_address, selector!("get_nonce"), 1); start_mock_call::>(starknet_address, selector!("bytecode"), [].span()); start_mock_call::(starknet_address, selector!("get_code_hash"), EMPTY_KECCAK); @@ -391,9 +391,9 @@ mod tests { assert_called(starknet_address, selector!("get_nonce")); assert_called(starknet_address, selector!("bytecode")); assert_called(starknet_address, selector!("get_code_hash")); - //TODO(starknet-foundry): we mocked the balanceOf call, but we should also check if it + //TODO(starknet-foundry): we mocked the balance_of call, but we should also check if it //was called with the right data - assert_called(native_token(), selector!("balanceOf")); + assert_called(native_token(), selector!("balance_of")); } #[test] @@ -439,7 +439,7 @@ mod tests { }; // When - start_mock_call::(native_token(), selector!("balanceOf"), 100); + start_mock_call::(native_token(), selector!("balance_of"), 100); start_mock_call::(starknet_address, selector!("get_nonce"), 1); start_mock_call::>(starknet_address, selector!("bytecode"), [].span()); start_mock_call::(starknet_address, selector!("get_code_hash"), EMPTY_KECCAK); @@ -450,9 +450,9 @@ mod tests { assert_called(starknet_address, selector!("get_nonce")); assert_called(starknet_address, selector!("bytecode")); assert_called(starknet_address, selector!("get_code_hash")); - //TODO(starknet-foundry): we mocked the balanceOf call, but we should also check if it + //TODO(starknet-foundry): we mocked the balance_of call, but we should also check if it //was called with the right data - assert_called(native_token(), selector!("balanceOf")); + assert_called(native_token(), selector!("balance_of")); } #[test] @@ -474,14 +474,14 @@ mod tests { }; // When - start_mock_call::(native_token(), selector!("balanceOf"), 50); + start_mock_call::(native_token(), selector!("balance_of"), 50); let account = AccountTrait::fetch_or_create(evm_address()); // Then assert_eq!(account, expected); - //TODO(starknet-foundry): we mocked the balanceOf call, but we should also check if it + //TODO(starknet-foundry): we mocked the balance_of call, but we should also check if it //was called with the right data - assert_called(native_token(), selector!("balanceOf")); + assert_called(native_token(), selector!("balance_of")); } } //TODO(starknet-foundry): add a test for get_jumpdests diff --git a/cairo/kakarot-ssj/crates/evm/src/precompiles/blake2f.cairo b/cairo/kakarot-ssj/crates/evm/src/precompiles/blake2f.cairo index ac16b81d2..8147956c5 100644 --- a/cairo/kakarot-ssj/crates/evm/src/precompiles/blake2f.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/precompiles/blake2f.cairo @@ -199,7 +199,7 @@ mod tests { vm.stack.push(9).unwrap(); // address vm.stack.push(0xFFFFFFFF).unwrap(); // gas - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_staticcall().unwrap(); let mut result: Array = Default::default(); diff --git a/cairo/kakarot-ssj/crates/evm/src/precompiles/ec_recover.cairo b/cairo/kakarot-ssj/crates/evm/src/precompiles/ec_recover.cairo index cfa2f68f9..833a635ab 100644 --- a/cairo/kakarot-ssj/crates/evm/src/precompiles/ec_recover.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/precompiles/ec_recover.cairo @@ -141,7 +141,7 @@ mod tests { vm.stack.push(0x1).unwrap(); // address vm.stack.push(0xFFFFFFFF).unwrap(); // gas - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_staticcall().unwrap(); let result = vm.memory.load(0x80); diff --git a/cairo/kakarot-ssj/crates/evm/src/precompiles/identity.cairo b/cairo/kakarot-ssj/crates/evm/src/precompiles/identity.cairo index e84ceaf80..af02a738b 100644 --- a/cairo/kakarot-ssj/crates/evm/src/precompiles/identity.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/precompiles/identity.cairo @@ -63,7 +63,7 @@ mod tests { vm.memory.store_with_expansion(0x2A, 0x1F); - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_staticcall().unwrap(); let result = vm.memory.load(0x3F); diff --git a/cairo/kakarot-ssj/crates/evm/src/precompiles/p256verify.cairo b/cairo/kakarot-ssj/crates/evm/src/precompiles/p256verify.cairo index f0bbc4948..3a292fc04 100644 --- a/cairo/kakarot-ssj/crates/evm/src/precompiles/p256verify.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/precompiles/p256verify.cairo @@ -155,7 +155,7 @@ mod tests { vm.stack.push(0x100).unwrap(); // address vm.stack.push(0xFFFFFFFF).unwrap(); // gas - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_staticcall().unwrap(); let mut result = Default::default(); @@ -216,7 +216,7 @@ mod tests { vm.stack.push(0x100).unwrap(); // address vm.stack.push(0xFFFFFFFF).unwrap(); // gas - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_staticcall().unwrap(); let mut result = Default::default(); diff --git a/cairo/kakarot-ssj/crates/evm/src/precompiles/sha256.cairo b/cairo/kakarot-ssj/crates/evm/src/precompiles/sha256.cairo index 60be11a69..2d8b931a6 100644 --- a/cairo/kakarot-ssj/crates/evm/src/precompiles/sha256.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/precompiles/sha256.cairo @@ -162,7 +162,7 @@ mod tests { vm.memory.store_with_expansion(0xFF, 0x0); - start_mock_call::(native_token(), selector!("balanceOf"), 0); + start_mock_call::(native_token(), selector!("balance_of"), 0); vm.exec_staticcall().unwrap(); let result = vm.memory.load(0x20); diff --git a/cairo/kakarot-ssj/crates/evm/src/state.cairo b/cairo/kakarot-ssj/crates/evm/src/state.cairo index 0ea8ce3ca..dcf1dc0a0 100644 --- a/cairo/kakarot-ssj/crates/evm/src/state.cairo +++ b/cairo/kakarot-ssj/crates/evm/src/state.cairo @@ -439,7 +439,7 @@ mod tests { is_created: false, }; - start_mock_call::(test_utils::native_token(), selector!("balanceOf"), 0); + start_mock_call::(test_utils::native_token(), selector!("balance_of"), 0); let account = state.get_account(evm_address); assert_eq!(account, expected_account); @@ -499,7 +499,7 @@ mod tests { is_created: false, }; - start_mock_call::(test_utils::native_token(), selector!("balanceOf"), 420); + start_mock_call::(test_utils::native_token(), selector!("balance_of"), 420); start_mock_call::< Span >(starknet_address, selector!("bytecode"), [0xab, 0xcd, 0xef].span()); @@ -540,7 +540,7 @@ mod tests { let code_hash = bytecode.compute_keccak256_hash(); start_mock_call::(starknet_address, selector!("storage"), value); - start_mock_call::(test_utils::native_token(), selector!("balanceOf"), 10000); + start_mock_call::(test_utils::native_token(), selector!("balance_of"), 10000); start_mock_call::>(starknet_address, selector!("bytecode"), bytecode); start_mock_call::(starknet_address, selector!("get_code_hash"), code_hash); start_mock_call::(starknet_address, selector!("get_nonce"), 1); @@ -759,7 +759,7 @@ mod tests { let mut state: State = Default::default(); let bytecode = [0xab, 0xcd, 0xef].span(); let code_hash = bytecode.compute_keccak256_hash(); - start_mock_call::(test_utils::native_token(), selector!("balanceOf"), 10000); + start_mock_call::(test_utils::native_token(), selector!("balance_of"), 10000); start_mock_call::>(starknet_address, selector!("bytecode"), bytecode); start_mock_call::(starknet_address, selector!("get_code_hash"), code_hash); start_mock_call::(starknet_address, selector!("get_nonce"), 1); From 8ddc64905892cad3d917b18cff58d655753805e4 Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Thu, 31 Oct 2024 14:52:58 +0100 Subject: [PATCH 8/9] remove MockContractUpgradeableV0 --- .../src/mocks/mock_contract_upgradeable.cairo | 38 ------------------- 1 file changed, 38 deletions(-) diff --git a/cairo/kakarot-ssj/crates/contracts/src/mocks/mock_contract_upgradeable.cairo b/cairo/kakarot-ssj/crates/contracts/src/mocks/mock_contract_upgradeable.cairo index f94fd9365..ad2d034dd 100644 --- a/cairo/kakarot-ssj/crates/contracts/src/mocks/mock_contract_upgradeable.cairo +++ b/cairo/kakarot-ssj/crates/contracts/src/mocks/mock_contract_upgradeable.cairo @@ -3,44 +3,6 @@ pub trait IMockContractUpgradeable { fn version(self: @TContractState) -> felt252; } -#[starknet::contract] -pub mod MockContractUpgradeableV0 { - use openzeppelin::upgrades::interface::IUpgradeable; - use openzeppelin::upgrades::upgradeable::UpgradeableComponent; - use starknet::{ClassHash}; - use super::IMockContractUpgradeable; - component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent); - - impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl; - - #[storage] - struct Storage { - #[substorage(v0)] - upgradeable: UpgradeableComponent::Storage - } - - #[event] - #[derive(Drop, starknet::Event)] - pub enum Event { - UpgradeableEvent: UpgradeableComponent::Event, - } - - #[abi(embed_v0)] - impl MockContractUpgradeableImpl of IMockContractUpgradeable { - fn version(self: @ContractState) -> felt252 { - 0 - } - } - - - #[abi(embed_v0)] - impl UpgradeableImpl of IUpgradeable { - fn upgrade(ref self: ContractState, new_class_hash: ClassHash) { - self.upgradeable.upgrade(new_class_hash); - } - } -} - #[starknet::contract] pub mod MockContractUpgradeableV1 { use openzeppelin::upgrades::interface::IUpgradeable; From e99857e33dbba30cbb864ebb78e5d72c165377df Mon Sep 17 00:00:00 2001 From: manlikeHB Date: Thu, 31 Oct 2024 15:41:48 +0100 Subject: [PATCH 9/9] - bump scarb version to 2.8.4 - bump OZ's version to 0.18.0 --- cairo/kakarot-ssj/.tool-versions | 2 +- cairo/kakarot-ssj/Scarb.lock | 60 ++++++++++++------- cairo/kakarot-ssj/Scarb.toml | 4 +- cairo/kakarot-ssj/crates/contracts/Scarb.toml | 2 +- cairo/kakarot-ssj/crates/evm/Scarb.toml | 2 +- 5 files changed, 42 insertions(+), 28 deletions(-) diff --git a/cairo/kakarot-ssj/.tool-versions b/cairo/kakarot-ssj/.tool-versions index 5248f18a0..4118adeda 100644 --- a/cairo/kakarot-ssj/.tool-versions +++ b/cairo/kakarot-ssj/.tool-versions @@ -1,2 +1,2 @@ -scarb 2.8.3 +scarb 2.8.4 starknet-foundry 0.31.0 diff --git a/cairo/kakarot-ssj/Scarb.lock b/cairo/kakarot-ssj/Scarb.lock index a02913e7f..f846d0583 100644 --- a/cairo/kakarot-ssj/Scarb.lock +++ b/cairo/kakarot-ssj/Scarb.lock @@ -38,11 +38,12 @@ source = "git+https://github.com/keep-starknet-strange/garaga.git#933784eee38113 [[package]] name = "openzeppelin" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" dependencies = [ "openzeppelin_access", "openzeppelin_account", + "openzeppelin_finance", "openzeppelin_governance", "openzeppelin_introspection", "openzeppelin_merkle_tree", @@ -55,8 +56,8 @@ dependencies = [ [[package]] name = "openzeppelin_access" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" dependencies = [ "openzeppelin_introspection", "openzeppelin_utils", @@ -64,68 +65,81 @@ dependencies = [ [[package]] name = "openzeppelin_account" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" dependencies = [ "openzeppelin_introspection", "openzeppelin_utils", ] +[[package]] +name = "openzeppelin_finance" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" +dependencies = [ + "openzeppelin_access", + "openzeppelin_token", +] + [[package]] name = "openzeppelin_governance" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" dependencies = [ "openzeppelin_access", + "openzeppelin_account", "openzeppelin_introspection", + "openzeppelin_token", ] [[package]] name = "openzeppelin_introspection" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" [[package]] name = "openzeppelin_merkle_tree" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" [[package]] name = "openzeppelin_presets" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" dependencies = [ "openzeppelin_access", "openzeppelin_account", + "openzeppelin_finance", "openzeppelin_introspection", "openzeppelin_token", "openzeppelin_upgrades", + "openzeppelin_utils", ] [[package]] name = "openzeppelin_security" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" [[package]] name = "openzeppelin_token" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" dependencies = [ "openzeppelin_account", - "openzeppelin_governance", "openzeppelin_introspection", + "openzeppelin_utils", ] [[package]] name = "openzeppelin_upgrades" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" [[package]] name = "openzeppelin_utils" -version = "0.16.0" -source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.16.0#ba00ce76a93dcf25c081ab2698da20690b5a1cfb" +version = "0.18.0" +source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487" [[package]] name = "snforge_scarb_plugin" diff --git a/cairo/kakarot-ssj/Scarb.toml b/cairo/kakarot-ssj/Scarb.toml index b0d420965..f41b131a0 100644 --- a/cairo/kakarot-ssj/Scarb.toml +++ b/cairo/kakarot-ssj/Scarb.toml @@ -4,14 +4,14 @@ members = ["crates/*"] [workspace.package] description = "Kakarot is an (zk)-Ethereum Virtual Machine implementation written in Cairo." documentation = "https://www.kakarot.org/" -cairo-version = "2.8.2" +cairo-version = "2.8.4" version = "0.1.0" readme = "README.md" repository = "https://github.com/kkrt-labs/kakarot-ssj/" license-file = "LICENSE" [workspace.dependencies] -starknet = "2.8.2" +starknet = "2.8.4" [workspace.tool.fmt] sort-module-level-items = true diff --git a/cairo/kakarot-ssj/crates/contracts/Scarb.toml b/cairo/kakarot-ssj/crates/contracts/Scarb.toml index 9a33710e8..507c17406 100644 --- a/cairo/kakarot-ssj/crates/contracts/Scarb.toml +++ b/cairo/kakarot-ssj/crates/contracts/Scarb.toml @@ -9,7 +9,7 @@ edition = "2024_07" starknet.workspace = true evm = { path = "../evm" } utils = { path = "../utils" } -openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag="v0.16.0" } +openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag="v0.18.0" } [tool] fmt.workspace = true diff --git a/cairo/kakarot-ssj/crates/evm/Scarb.toml b/cairo/kakarot-ssj/crates/evm/Scarb.toml index 055e0c4e7..aedb55e64 100644 --- a/cairo/kakarot-ssj/crates/evm/Scarb.toml +++ b/cairo/kakarot-ssj/crates/evm/Scarb.toml @@ -10,7 +10,7 @@ starknet.workspace = true utils = { path = "../utils" } contracts = { path = "../contracts" } garaga = { git = "https://github.com/keep-starknet-strange/garaga.git" } -openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag="v0.16.0" } +openzeppelin = { git = "https://github.com/openzeppelin/cairo-contracts", tag="v0.18.0" } [dev-dependencies] snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry.git", tag = "v0.31.0" }