Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

use OZ contracts #1558

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cairo/kakarot-ssj/.tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scarb 2.8.3
scarb 2.8.4
starknet-foundry 0.31.0
102 changes: 100 additions & 2 deletions cairo/kakarot-ssj/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,109 @@ source = "git+https://github.com/keep-starknet-strange/garaga.git#933784eee38113

[[package]]
name = "openzeppelin"
version = "0.1.0"
version = "0.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"
dependencies = [
"snforge_std",
"openzeppelin_access",
"openzeppelin_account",
"openzeppelin_finance",
"openzeppelin_governance",
"openzeppelin_introspection",
"openzeppelin_merkle_tree",
"openzeppelin_presets",
"openzeppelin_security",
"openzeppelin_token",
"openzeppelin_upgrades",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_access"
version = "0.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"
dependencies = [
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_account"
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.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.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"

[[package]]
name = "openzeppelin_merkle_tree"
version = "0.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"

[[package]]
name = "openzeppelin_presets"
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.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"

[[package]]
name = "openzeppelin_token"
version = "0.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"
dependencies = [
"openzeppelin_account",
"openzeppelin_introspection",
"openzeppelin_utils",
]

[[package]]
name = "openzeppelin_upgrades"
version = "0.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"

[[package]]
name = "openzeppelin_utils"
version = "0.18.0"
source = "git+https://github.com/openzeppelin/cairo-contracts?tag=v0.18.0#2f37306b490e63c0afa9e33ad192ba428141b487"

[[package]]
name = "snforge_scarb_plugin"
version = "0.31.0"
Expand Down
4 changes: 2 additions & 2 deletions cairo/kakarot-ssj/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions cairo/kakarot-ssj/crates/contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ 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.18.0" }

[tool]
fmt.workspace = true

[[target.starknet-contract]]
casm = true
casm-add-pythonic-hints = true
build-external-contracts = ["openzeppelin::token::erc20::erc20::ERC20"]

[lib]
name = "contracts"
Expand Down
19 changes: 9 additions & 10 deletions cairo/kakarot-ssj/crates/contracts/src/account_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,22 @@ 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 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::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
use openzeppelin::access::ownable::OwnableComponent;
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};
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<ContractState>;
impl OwnableInternal = ownable_component::InternalImpl<ContractState>;
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
impl InternalImplOwnable = OwnableComponent::InternalImpl<ContractState>;


const VERSION: u32 = 000_001_000;
Expand All @@ -93,14 +91,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)]
Expand Down Expand Up @@ -132,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::<u256>::MAX);

kakarot.register_account(evm_address);
Expand Down
2 changes: 0 additions & 2 deletions cairo/kakarot-ssj/crates/contracts/src/components.cairo

This file was deleted.

91 changes: 0 additions & 91 deletions cairo/kakarot-ssj/crates/contracts/src/components/ownable.cairo

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand Down
Loading
Loading