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 6 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
88 changes: 86 additions & 2 deletions cairo/kakarot-ssj/Scarb.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions cairo/kakarot-ssj/crates/contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ 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" }
manlikeHB marked this conversation as resolved.
Show resolved Hide resolved

[tool]
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"]
manlikeHB marked this conversation as resolved.
Show resolved Hide resolved

[lib]
name = "contracts"
Expand Down
18 changes: 10 additions & 8 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,25 @@ 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::access::ownable::OwnableComponent;
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
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>;
#[abi(embed_v0)]
impl OwnableCamelOnlyImpl =
manlikeHB marked this conversation as resolved.
Show resolved Hide resolved
OwnableComponent::OwnableCamelOnlyImpl<ContractState>;
impl InternalImplOwnable = OwnableComponent::InternalImpl<ContractState>;


const VERSION: u32 = 000_001_000;
Expand All @@ -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)]
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.

30 changes: 17 additions & 13 deletions cairo/kakarot-ssj/crates/contracts/src/kakarot_core/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ pub mod KakarotCore {
StoragePointerWriteAccess
};
use core::starknet::{EthAddress, ContractAddress, ClassHash, get_contract_address};
use crate::components::ownable::{ownable_component};
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: ownable_component, storage: ownable, event: OwnableEvent);
component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent);

component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
component!(path: UpgradeableComponent, storage: upgradeable, event: UpgradeableEvent);
/// STORAGE ///

#[storage]
Expand All @@ -36,18 +35,20 @@ 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,
upgradeable: UpgradeableComponent::Storage,
}

/// EVENTS ///

#[event]
#[derive(Drop, starknet::Event)]
pub enum Event {
OwnableEvent: ownable_component::Event,
UpgradeableEvent: upgradeable_component::Event,
#[flat]
OwnableEvent: OwnableComponent::Event,
#[flat]
UpgradeableEvent: UpgradeableComponent::Event,
AccountDeployed: AccountDeployed,
AccountClassHashChange: AccountClassHashChange,
EOAClassHashChange: EOAClassHashChange,
Expand Down Expand Up @@ -114,7 +115,10 @@ pub mod KakarotCore {

// Public-facing "ownable" functions
#[abi(embed_v0)]
impl OwnableImpl = ownable_component::Ownable<ContractState>;
impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
#[abi(embed_v0)]
impl OwnableCamelOnlyImpl =
manlikeHB marked this conversation as resolved.
Show resolved Hide resolved
OwnableComponent::OwnableCamelOnlyImpl<ContractState>;

/// Public-facing "ethereum" functions
/// Used to make EVM-related actions through Kakarot.
Expand Down Expand Up @@ -147,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 {
Expand Down Expand Up @@ -211,8 +215,8 @@ pub mod KakarotCore {
/// INTERNAL-FACING FUNCTIONS ///

// Internal-facing "ownable" functions
impl OwnableInternalImpl = ownable_component::InternalImpl<ContractState>;
impl InternalImplOwnable = OwnableComponent::InternalImpl<ContractState>;

// Internal-facing "upgradeable" functions
impl UpgradeableImpl = upgradeable_component::Upgradeable<ContractState>;
impl UpgradeableInternalImpl = UpgradeableComponent::InternalImpl<ContractState>;
}
5 changes: 4 additions & 1 deletion cairo/kakarot-ssj/crates/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pub mod account_contract;
pub mod cairo1_helpers;
pub mod components;

pub mod errors;

Expand Down Expand Up @@ -35,3 +34,7 @@ pub mod test_contracts {
pub mod mocks {
pub mod cairo1_helpers_fixture;
}

pub mod token {
pub mod erc20;
}
Loading
Loading