Skip to content

Commit

Permalink
docs: add code doc (#980)
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat authored Sep 26, 2024
1 parent 5352614 commit 518e3c0
Show file tree
Hide file tree
Showing 63 changed files with 1,176 additions and 545 deletions.
14 changes: 7 additions & 7 deletions crates/contracts/src/account_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ pub trait IAccount<TContractState> {

#[starknet::contract(account)]
pub mod AccountContract {
use contracts::components::ownable::IOwnable;
use contracts::components::ownable::ownable_component::InternalTrait;
use contracts::components::ownable::ownable_component;
use contracts::errors::KAKAROT_REENTRANCY;
use contracts::kakarot_core::eth_rpc::{IEthRPCDispatcher, IEthRPCDispatcherTrait};
use contracts::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait};
use contracts::storage::StorageBytecode;
use core::cmp::min;
use core::num::traits::Bounded;
use core::num::traits::zero::Zero;
Expand All @@ -66,6 +59,13 @@ 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 super::OutsideExecution;
use utils::eth_transaction::transaction::TransactionUnsignedTrait;
Expand Down
11 changes: 5 additions & 6 deletions crates/contracts/src/kakarot_core/eth_rpc.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait};
use contracts::kakarot_core::interface::IKakarotCore;
use contracts::kakarot_core::kakarot::{KakarotCore, KakarotCore::{KakarotCoreState}};
use core::num::traits::Zero;
use core::starknet::get_tx_info;
use core::starknet::{EthAddress, get_caller_address};
use crate::account_contract::{IAccountDispatcher, IAccountDispatcherTrait};
use crate::kakarot_core::interface::IKakarotCore;
use crate::kakarot_core::kakarot::{KakarotCore, KakarotCore::{KakarotCoreState}};
use evm::backend::starknet_backend;
use evm::backend::validation::validate_eth_tx;
use evm::model::{TransactionResult, Address};
Expand Down Expand Up @@ -216,8 +216,8 @@ fn is_view(self: @KakarotCore::ContractState) -> bool {

#[cfg(test)]
mod tests {
use contracts::kakarot_core::KakarotCore;
use contracts::kakarot_core::eth_rpc::IEthRPC;
use crate::kakarot_core::KakarotCore;
use crate::kakarot_core::eth_rpc::IEthRPC;
use snforge_std::{start_cheat_chain_id_global, stop_cheat_chain_id_global};
use utils::constants::POW_2_53;

Expand Down Expand Up @@ -264,4 +264,3 @@ mod tests {
tear_down();
}
}

8 changes: 4 additions & 4 deletions crates/contracts/src/kakarot_core/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ const INVOKE_ETH_CALL_FORBIDDEN: felt252 = 'KKT: Cannot invoke eth_call';

#[starknet::contract]
pub mod KakarotCore {
use contracts::components::ownable::{ownable_component};
use contracts::components::upgradeable::{IUpgradeable, upgradeable_component};
use contracts::kakarot_core::eth_rpc;
use contracts::kakarot_core::interface::IKakarotCore;
use core::num::traits::Zero;
use core::starknet::event::EventEmitter;
use core::starknet::storage::{
Map, StorageMapReadAccess, StorageMapWriteAccess, StoragePointerReadAccess,
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 utils::helpers::compute_starknet_address;

Expand Down
2 changes: 1 addition & 1 deletion crates/contracts/src/mocks/cairo1_helpers_fixture.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#[starknet::contract]
pub mod Cairo1HelpersFixture {
use contracts::cairo1_helpers::embeddable_impls;
use crate::cairo1_helpers::embeddable_impls;

const VERSION: felt252 = 2;

Expand Down
4 changes: 2 additions & 2 deletions crates/contracts/src/storage.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use contracts::account_contract::AccountContract::unsafe_new_contract_state as account_contract_state;
use core::ops::DerefMut;
use core::ops::SnapshotDeref;
use core::starknet::storage::{
Expand All @@ -7,6 +6,7 @@ use core::starknet::storage::{
use core::starknet::storage_access::StorageBaseAddress;
use core::starknet::syscalls::{storage_read_syscall, storage_write_syscall};
use core::starknet::{SyscallResult, Store, StorageAddress};
use crate::account_contract::AccountContract::unsafe_new_contract_state as account_contract_state;
use utils::utils::{pack_bytes, load_packed_bytes};

/// A wrapper type for the bytecode storage. Packing / unpacking is done transparently inside the
Expand Down Expand Up @@ -87,8 +87,8 @@ impl StoreBytecode of Store<StorageBytecode> {

#[cfg(test)]
mod tests {
use contracts::account_contract::AccountContract::unsafe_new_contract_state as account_contract_state;
use core::starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
use crate::account_contract::AccountContract::unsafe_new_contract_state as account_contract_state;
use starknet::storage_access::Store;
use starknet::storage_access::{
StorageBaseAddress, StorageAddress, storage_base_address_from_felt252
Expand Down
8 changes: 4 additions & 4 deletions crates/contracts/src/test_contracts/test_upgradeable.cairo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use contracts::components::upgradeable::{upgradeable_component};
use crate::components::upgradeable::{upgradeable_component};

use upgradeable_component::{UpgradeableImpl};

Expand All @@ -9,7 +9,7 @@ pub trait IMockContractUpgradeable<TContractState> {

#[starknet::contract]
pub mod MockContractUpgradeableV0 {
use contracts::components::upgradeable::{upgradeable_component};
use crate::components::upgradeable::{upgradeable_component};
use super::IMockContractUpgradeable;
component!(path: upgradeable_component, storage: upgradeable, event: UpgradeableEvent);

Expand Down Expand Up @@ -38,7 +38,7 @@ pub mod MockContractUpgradeableV0 {

#[starknet::contract]
pub mod MockContractUpgradeableV1 {
use contracts::components::upgradeable::{upgradeable_component};
use crate::components::upgradeable::{upgradeable_component};
use super::IMockContractUpgradeable;
component!(path: upgradeable_component, storage: upgradeable, event: upgradeableEvent);

Expand All @@ -64,8 +64,8 @@ pub mod MockContractUpgradeableV1 {

#[cfg(test)]
mod tests {
use contracts::components::upgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait};
use core::starknet::syscalls::{deploy_syscall};
use crate::components::upgradeable::{IUpgradeableDispatcher, IUpgradeableDispatcherTrait};
use snforge_std::{declare, DeclareResultTrait};
use starknet::{ClassHash};
use super::{IMockContractUpgradeableDispatcher, IMockContractUpgradeableDispatcherTrait};
Expand Down
8 changes: 4 additions & 4 deletions crates/contracts/src/test_utils.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait};
use contracts::kakarot_core::{
interface::IExtendedKakarotCoreDispatcher, interface::IExtendedKakarotCoreDispatcherTrait
};
use core::result::ResultTrait;
use core::starknet::syscalls::deploy_syscall;
use core::starknet::{EthAddress, ContractAddress};
use crate::account_contract::{IAccountDispatcher, IAccountDispatcherTrait};
use crate::kakarot_core::{
interface::IExtendedKakarotCoreDispatcher, interface::IExtendedKakarotCoreDispatcherTrait
};
use evm::model::{Address};

use evm::test_utils::{other_starknet_address, sequencer_evm_address, chain_id};
Expand Down
6 changes: 3 additions & 3 deletions crates/contracts/src/uninitialized_account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ trait IAccount<TContractState> {

#[starknet::contract]
pub mod UninitializedAccount {
use contracts::components::ownable::ownable_component::InternalTrait;
use contracts::components::ownable::ownable_component;
use contracts::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait};
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 crate::kakarot_core::interface::{IKakarotCoreDispatcher, IKakarotCoreDispatcherTrait};

// Add ownable component
component!(path: ownable_component, storage: ownable, event: OwnableEvent);
Expand Down
20 changes: 10 additions & 10 deletions crates/evm/src/backend/starknet_backend.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use core::starknet::storage::StoragePointerReadAccess;
use core::starknet::syscalls::{deploy_syscall};
use core::starknet::syscalls::{emit_event_syscall};
use core::starknet::{EthAddress, get_block_info, SyscallResultTrait};
use evm::errors::{ensure, EVMError};
use evm::model::{Address, AddressTrait, Environment, Account, AccountTrait};
use evm::model::{Transfer};
use evm::state::{State, StateTrait};
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 utils::constants::BURN_ADDRESS;
use utils::constants;
Expand Down Expand Up @@ -247,14 +247,14 @@ fn commit_storage(ref self: State) -> Result<(), EVMError> {
#[cfg(test)]
mod tests {
use core::starknet::ClassHash;
use evm::backend::starknet_backend;
use evm::model::Address;
use evm::model::account::Account;
use evm::state::{State, StateTrait};
use evm::test_utils::{
use crate::backend::starknet_backend;
use crate::model::Address;
use crate::model::account::Account;
use crate::state::{State, StateTrait};
use crate::test_utils::{
setup_test_environment, uninitialized_account, account_contract, register_account
};
use evm::test_utils::{evm_address};
use crate::test_utils::{evm_address};
use snforge_std::{test_address, start_mock_call, get_class_hash};
use snforge_utils::snforge_utils::{assert_not_called, assert_called};
use super::commit_storage;
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/backend/validation.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use contracts::kakarot_core::eth_rpc::IEthRPC;
use core::ops::SnapshotDeref;
use core::starknet::storage::{StoragePointerReadAccess};
use core::starknet::{get_caller_address};
use evm::gas;
use crate::gas;
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
use starknet::storage::StorageTrait;
use utils::eth_transaction::check_gas_fee;
Expand Down
14 changes: 7 additions & 7 deletions crates/evm/src/call_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use contracts::kakarot_core::interface::IKakarotCore;
use core::cmp::min;
use core::starknet::EthAddress;

use evm::errors::EVMError;
use evm::interpreter::EVMTrait;
use evm::memory::MemoryTrait;
use evm::model::vm::{VM, VMTrait};
use evm::model::{Address, Message, ExecutionResultStatus};
use evm::stack::StackTrait;
use evm::state::StateTrait;
use crate::errors::EVMError;
use crate::interpreter::EVMTrait;
use crate::memory::MemoryTrait;
use crate::model::vm::{VM, VMTrait};
use crate::model::{Address, Message, ExecutionResultStatus};
use crate::stack::StackTrait;
use crate::state::StateTrait;
use utils::constants;
use utils::set::SetTrait;
use utils::traits::{BoolIntoNumeric, U256TryIntoResult};
Expand Down
20 changes: 10 additions & 10 deletions crates/evm/src/create_helpers.cairo
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use core::num::traits::Bounded;
use core::num::traits::Zero;
use core::starknet::EthAddress;
use evm::errors::{ensure, EVMError};
use evm::gas;
use evm::interpreter::EVMTrait;
use evm::memory::MemoryTrait;
use evm::model::Message;
use evm::model::account::{Account, AccountTrait};
use evm::model::vm::{VM, VMTrait};
use evm::model::{ExecutionResult, ExecutionResultTrait, ExecutionResultStatus};
use evm::stack::StackTrait;
use evm::state::StateTrait;
use crate::errors::{ensure, EVMError};
use crate::gas;
use crate::interpreter::EVMTrait;
use crate::memory::MemoryTrait;
use crate::model::Message;
use crate::model::account::{Account, AccountTrait};
use crate::model::vm::{VM, VMTrait};
use crate::model::{ExecutionResult, ExecutionResultTrait, ExecutionResultStatus};
use crate::stack::StackTrait;
use crate::state::StateTrait;
use utils::address::{compute_contract_address, compute_create2_contract_address};
use utils::constants;
use utils::helpers::ceil32;
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/gas.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use core::cmp::min;
use core::num::traits::CheckedAdd;
use evm::errors::EVMError;
use crate::errors::EVMError;
use utils::eth_transaction::common::TxKindTrait;
use utils::eth_transaction::eip2930::{AccessListItem};
use utils::eth_transaction::transaction::{Transaction, TransactionTrait};
Expand Down Expand Up @@ -275,11 +275,11 @@ pub fn calculate_intrinsic_gas_cost(tx: @Transaction) -> u64 {
mod tests {
use core::starknet::EthAddress;

use evm::gas::{
use crate::gas::{
calculate_intrinsic_gas_cost, calculate_memory_gas_cost, ACCESS_LIST_ADDRESS,
ACCESS_LIST_STORAGE_KEY
};
use evm::test_utils::evm_address;
use crate::test_utils::evm_address;
use utils::eth_transaction::eip2930::{AccessListItem, TxEip2930};
use utils::eth_transaction::legacy::TxLegacy;
use utils::eth_transaction::transaction::Transaction;
Expand Down
22 changes: 11 additions & 11 deletions crates/evm/src/instructions/block_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use core::starknet::SyscallResultTrait;
use core::starknet::syscalls::get_block_hash_syscall;

use evm::errors::EVMError;
use crate::errors::EVMError;

use evm::gas;
use evm::model::vm::{VM, VMTrait};
use evm::stack::StackTrait;
use evm::state::StateTrait;
use crate::gas;
use crate::model::vm::{VM, VMTrait};
use crate::stack::StackTrait;
use crate::state::StateTrait;
use utils::constants::MIN_BASE_FEE_PER_BLOB_GAS;
use utils::traits::{EthAddressTryIntoResultContractAddress, EthAddressIntoU256};

Expand Down Expand Up @@ -140,12 +140,12 @@ pub impl BlockInformation of BlockInformationTrait {
#[cfg(test)]
mod tests {
use core::result::ResultTrait;
use evm::instructions::BlockInformationTrait;
use evm::model::account::Account;
use evm::model::vm::VMTrait;
use evm::stack::StackTrait;
use evm::state::StateTrait;
use evm::test_utils::{VMBuilderTrait, gas_price, setup_test_environment};
use crate::instructions::BlockInformationTrait;
use crate::model::account::Account;
use crate::model::vm::VMTrait;
use crate::stack::StackTrait;
use crate::state::StateTrait;
use crate::test_utils::{VMBuilderTrait, gas_price, setup_test_environment};
use snforge_std::{start_cheat_block_number_global, start_cheat_block_timestamp_global};
use utils::constants::EMPTY_KECCAK;
use utils::constants;
Expand Down
14 changes: 7 additions & 7 deletions crates/evm/src/instructions/comparison_operations.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use core::num::traits::Bounded;
use evm::errors::EVMError;
use evm::gas;
use evm::model::vm::{VM, VMTrait};
use crate::errors::EVMError;
use crate::gas;
use crate::model::vm::{VM, VMTrait};
// Internal imports
use evm::stack::StackTrait;
use crate::stack::StackTrait;
use utils::constants::{POW_2_127};
use utils::i256::i256;
use utils::math::{Bitshift, WrappingBitshift};
Expand Down Expand Up @@ -198,9 +198,9 @@ pub impl ComparisonAndBitwiseOperations of ComparisonAndBitwiseOperationsTrait {
#[cfg(test)]
mod tests {
use core::num::traits::Bounded;
use evm::instructions::ComparisonAndBitwiseOperationsTrait;
use evm::stack::StackTrait;
use evm::test_utils::VMBuilderTrait;
use crate::instructions::ComparisonAndBitwiseOperationsTrait;
use crate::stack::StackTrait;
use crate::test_utils::VMBuilderTrait;

#[test]
fn test_eq_same_pair() {
Expand Down
16 changes: 8 additions & 8 deletions crates/evm/src/instructions/duplication_operations.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! Duplication Operations.

// Internal imports
use evm::errors::EVMError;
use evm::gas;
use evm::model::vm::{VM, VMTrait};
use evm::stack::StackTrait;
use crate::errors::EVMError;
use crate::gas;
use crate::model::vm::{VM, VMTrait};
use crate::stack::StackTrait;

/// Generic DUP operation
#[inline(always)]
Expand Down Expand Up @@ -115,10 +115,10 @@ pub impl DuplicationOperations of DuplicationOperationsTrait {

#[cfg(test)]
mod tests {
use evm::instructions::DuplicationOperationsTrait;
use evm::stack::Stack;
use evm::stack::StackTrait;
use evm::test_utils::VMBuilderTrait;
use crate::instructions::DuplicationOperationsTrait;
use crate::stack::Stack;
use crate::stack::StackTrait;
use crate::test_utils::VMBuilderTrait;


// ensures all values start from index `from` upto index `to` of stack are `0x0`
Expand Down
Loading

0 comments on commit 518e3c0

Please sign in to comment.