Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
sync with 2.8.2
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 9, 2024
1 parent ecebd66 commit 682e099
Show file tree
Hide file tree
Showing 27 changed files with 79 additions and 210 deletions.
5 changes: 3 additions & 2 deletions crates/contracts/src/account_contract.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! Address <=> Starknet Address

use core::starknet::account::{Call};
use core::starknet::{EthAddress, ClassHash};
use core::starknet::{EthAddress, ClassHash, ContractAddress};

#[derive(Copy, Drop, Serde, Debug)]
pub struct OutsideExecution {
Expand Down Expand Up @@ -64,7 +64,8 @@ pub mod AccountContract {
};
use core::starknet::syscalls::{call_contract_syscall, replace_class_syscall};
use core::starknet::{
EthAddress, ClassHash, VALIDATED, get_caller_address, get_contract_address, get_tx_info
EthAddress, ClassHash, VALIDATED, get_caller_address, get_contract_address, get_tx_info,
get_block_timestamp
};
use core::traits::TryInto;
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
Expand Down
4 changes: 2 additions & 2 deletions crates/contracts/src/cairo1_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,12 @@ pub mod embeddable_impls {
use core::{starknet, starknet::SyscallResultTrait};
use evm::errors::EVMError;
use evm::precompiles::Blake2f;
use evm::precompiles::EcAdd;
use evm::precompiles::EcMul;
use evm::precompiles::EcRecover;
use evm::precompiles::Identity;
use evm::precompiles::ModExp;
use evm::precompiles::Sha256;
use evm::precompiles::EcAdd;
use evm::precompiles::EcMul;
use utils::helpers::U256Trait;


Expand Down
5 changes: 4 additions & 1 deletion crates/contracts/src/kakarot_core/kakarot.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub mod KakarotCore {
use evm::errors::{EVMError, ensure, EVMErrorTrait,};
use evm::gas;
use evm::model::account::AccountTrait;
use evm::model::{Message, TransactionResult, TransactionResultTrait, Address};
use evm::model::{
Message, TransactionResult, TransactionResultTrait, ExecutionSummaryTrait, Address
};
use evm::precompiles::eth_precompile_addresses;
use evm::state::StateTrait;
use evm::{EVMTrait};
use utils::address::compute_contract_address;
Expand Down
13 changes: 9 additions & 4 deletions crates/contracts/src/test_utils.cairo
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
use contracts::account_contract::{IAccountDispatcher, IAccountDispatcherTrait};
use contracts::kakarot_core::{ interface::IExtendedKakarotCoreDispatcher, interface::IExtendedKakarotCoreDispatcherTrait };
use contracts::kakarot_core::{
interface::IExtendedKakarotCoreDispatcher, interface::IExtendedKakarotCoreDispatcherTrait
};
use core::result::ResultTrait;
use core::starknet::{ EthAddress, ContractAddress, deploy_syscall };
use core::starknet::{EthAddress, ContractAddress, deploy_syscall};
use evm::model::{Address};

use evm::test_utils::{ other_starknet_address, sequencer_evm_address };
use evm::test_utils::{other_starknet_address, sequencer_evm_address};
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
use snforge_std::{ declare, DeclareResultTrait, start_cheat_caller_address, start_cheat_sequencer_address_global, stop_cheat_caller_address, start_cheat_caller_address_global };
use snforge_std::{
declare, DeclareResultTrait, start_cheat_caller_address, start_cheat_sequencer_address_global,
stop_cheat_caller_address, start_cheat_caller_address_global
};
use utils::constants::BLOCK_GAS_LIMIT;
use utils::eth_transaction::LegacyTransaction;

Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/backend/starknet_backend.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ mod tests {
use evm::model::Address;
use evm::model::account::Account;
use evm::state::{State, StateTrait};
use evm::test_utils::evm_address;
use evm::test_utils::{
setup_test_storages, uninitialized_account, account_contract, register_account
};
use evm::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 snforge_std::{test_address, start_mock_call, get_class_hash};
use snforge_utils::snforge_utils::{assert_not_called, assert_called};
use utils::helpers::compute_starknet_address;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/create_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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::{
Expand Down Expand Up @@ -184,4 +183,5 @@ pub impl CreateHelpersImpl of CreateHelpers {
mod tests {
//TODO: test create helpers


}
4 changes: 3 additions & 1 deletion crates/evm/src/gas.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ mod tests {
ACCESS_LIST_STORAGE_KEY
};
use evm::test_utils::evm_address;
use utils::eth_transaction::{ EthereumTransaction, LegacyTransaction, AccessListTransaction, AccessListItem };
use utils::eth_transaction::{
EthereumTransaction, LegacyTransaction, AccessListTransaction, AccessListItem
};
use utils::helpers::ToBytes;

#[test]
Expand Down
5 changes: 2 additions & 3 deletions crates/evm/src/instructions/block_information.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,14 @@ 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_storages };
use snforge_std::{ start_cheat_block_number_global, start_cheat_block_timestamp_global };
use evm::test_utils::{VMBuilderTrait, gas_price, setup_test_storages};
use snforge_std::{start_cheat_block_number_global, start_cheat_block_timestamp_global};
use utils::constants;
use utils::traits::{EthAddressIntoU256};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ mod tests {
use evm::model::{Account, Address};
use evm::stack::StackTrait;
use evm::state::StateTrait;
use evm::test_utils::{ VMBuilderTrait, origin, callvalue, gas_price };
use evm::test_utils::{VMBuilderTrait, origin, callvalue, gas_price};
use snforge_std::test_address;
use utils::helpers::{u256_to_bytes_array, ArrayExtTrait, compute_starknet_address};
use utils::traits::{EthAddressIntoU256};
Expand Down
20 changes: 10 additions & 10 deletions crates/evm/src/instructions/logging_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ fn exec_log_i(ref self: VM, topics_len: u8) -> Result<(), EVMError> {
let size = self.stack.pop_usize()?;
let topics: Array<u256> = self.stack.pop_n(topics_len.into())?;

let memory_expansion = gas::memory_expansion(self.memory.size(), [(offset, size)].span());
self.memory.ensure_length(memory_expansion.new_size);
self
.charge_gas(
gas::LOG
+ topics_len.into() * gas::LOGTOPIC
+ size.into() * gas::LOGDATA
+ memory_expansion.expansion_cost
)?;
let memory_expansion = gas::memory_expansion(self.memory.size(), [(offset, size)].span());
self.memory.ensure_length(memory_expansion.new_size);
self
.charge_gas(
gas::LOG
+ topics_len.into() * gas::LOGTOPIC
+ size.into() * gas::LOGDATA
+ memory_expansion.expansion_cost
)?;

let mut data: Array<u8> = Default::default();
self.memory.load_n(size, ref data, offset);
Expand All @@ -87,7 +87,7 @@ fn exec_log_i(ref self: VM, topics_len: u8) -> Result<(), EVMError> {
mod tests {
use core::num::traits::Bounded;
use core::result::ResultTrait;
use evm::errors::{ EVMError, TYPE_CONVERSION_ERROR };
use evm::errors::{EVMError, TYPE_CONVERSION_ERROR};
use evm::instructions::LoggingOperationsTrait;
use evm::memory::MemoryTrait;
use evm::stack::StackTrait;
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/instructions/memory_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ mod tests {
use evm::stack::StackTrait;
use evm::state::StateTrait;
use evm::test_utils::{
evm_address, VMBuilderTrait, MemoryTestUtilsTrait, setup_test_storages, register_account, uninitialized_account,
native_token
evm_address, VMBuilderTrait, MemoryTestUtilsTrait, setup_test_storages, register_account,
uninitialized_account, native_token
};
use snforge_std::{test_address, start_mock_call, store};
use snforge_utils::snforge_utils::store_evm;
Expand Down
6 changes: 3 additions & 3 deletions crates/evm/src/instructions/system_operations.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,12 @@ mod tests {
use evm::memory::MemoryTrait;
use evm::model::account::{Account};
use evm::model::vm::VMTrait;
use evm::model::{ AccountTrait, Address };
use evm::model::{AccountTrait, Address};
use evm::stack::StackTrait;
use evm::state::{StateTrait};
use evm::test_utils::{
VMBuilderTrait, MemoryTestUtilsTrait, native_token, evm_address, test_dual_address, other_evm_address,
setup_test_storages, register_account, origin, uninitialized_account
VMBuilderTrait, MemoryTestUtilsTrait, native_token, evm_address, test_dual_address,
other_evm_address, setup_test_storages, register_account, origin, uninitialized_account
};
use openzeppelin::token::erc20::interface::{IERC20CamelDispatcher, IERC20CamelDispatcherTrait};
use snforge_std::{test_address, start_mock_call};
Expand Down
3 changes: 1 addition & 2 deletions crates/evm/src/memory.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ impl MemoryImpl of MemoryTrait {
/// * `offset` - The offset within memory to store the byte at.
#[inline(always)]
fn store_byte(ref self: Memory, value: u8, offset: usize) {

let nonzero_16: NonZero<u32> = 16_u32.try_into().unwrap();

// Compute actual offset in Memory, given active_segment of Memory (current Execution
Expand Down Expand Up @@ -623,7 +622,7 @@ mod tests {
use core::num::traits::Bounded;
use evm::memory::{MemoryTrait, InternalMemoryTrait};
use utils::constants::{POW_2_8, POW_2_56, POW_2_64, POW_2_120};
use utils::{ math::Exponentiation, math::WrappingExponentiation, helpers, helpers::SpanExtTrait };
use utils::{math::Exponentiation, math::WrappingExponentiation, helpers, helpers::SpanExtTrait};


fn load_should_load_an_element_from_the_memory_with_offset_stored_with_store_n(
Expand Down
1 change: 0 additions & 1 deletion crates/evm/src/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ pub struct Transfer {

#[cfg(test)]
mod tests {

mod test_is_deployed {
use evm::model::AddressTrait;
use evm::test_utils;
Expand Down
14 changes: 7 additions & 7 deletions crates/evm/src/model/vm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ pub impl VMImpl of VMTrait {
mod tests {
use evm::errors::DebugEVMError;
use evm::errors::EVMError;
use evm::model::vm::VMTrait;
use evm::model::Message;
use evm::test_utils::{ tx_gas_limit, VMBuilderTrait };
use evm::model::vm::VMTrait;
use evm::test_utils::{tx_gas_limit, VMBuilderTrait};

#[test]
fn test_vm_default() {
Expand Down Expand Up @@ -258,11 +258,11 @@ mod tests {

let mut vm = VMTrait::new(message, Default::default());

assert!(vm.is_valid_jump(0x3) , "expected jump to be valid");
assert!(vm.is_valid_jump(0x9) , "expected jump to be valid");
assert!(vm.is_valid_jump(0x3), "expected jump to be valid");
assert!(vm.is_valid_jump(0x9), "expected jump to be valid");

assert!(!vm.is_valid_jump(0x4) , "expected jump to be invalid");
assert!(!vm.is_valid_jump(0x5) , "expected jump to be invalid");
assert!(!vm.is_valid_jump(0x4), "expected jump to be invalid");
assert!(!vm.is_valid_jump(0x5), "expected jump to be invalid");
}

#[test]
Expand All @@ -271,6 +271,6 @@ mod tests {
message.code = [0x60, 0x5B, 0x60, 0x00].span();

let mut vm = VMTrait::new(message, Default::default());
assert!(!vm.is_valid_jump(0x1) , "expected false");
assert!(!vm.is_valid_jump(0x1), "expected false");
}
}
13 changes: 3 additions & 10 deletions crates/evm/src/precompiles.cairo
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
mod blake2f;

mod ec_add;
// use ec_add::EcAdd;

mod ec_mul;
// use ec_mul::EcMul;

mod ec_recover;

Expand All @@ -15,7 +13,10 @@ mod modexp;
mod p256verify;

mod sha256;

pub use blake2f::Blake2f;
pub use ec_add::EcAdd;
pub use ec_mul::EcMul;
pub use ec_recover::EcRecover;
pub use identity::Identity;
pub use modexp::ModExp;
Expand All @@ -27,14 +28,6 @@ use core::traits::Into;
use evm::errors::EVMError;
use evm::model::vm::VM;
use evm::model::vm::VMTrait;
use evm::precompiles::blake2f::Blake2f;
use evm::precompiles::ec_add::EcAdd;
use evm::precompiles::ec_mul::EcMul;
use evm::precompiles::ec_recover::EcRecover;
use evm::precompiles::identity::Identity;
use evm::precompiles::modexp::ModExp;
use evm::precompiles::p256verify::P256Verify;
use evm::precompiles::sha256::Sha256;

use utils::set::{Set};

Expand Down
2 changes: 1 addition & 1 deletion crates/evm/src/precompiles/blake2f.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ mod tests {
blake2_precompile_fail_wrong_length_input_3_test_case, blake2_precompile_pass_1_test_case,
blake2_precompile_pass_0_test_case, blake2_precompile_pass_2_test_case
};
use evm::test_utils::{ VMBuilderTrait, native_token, setup_test_storages };
use evm::test_utils::{VMBuilderTrait, native_token, setup_test_storages};
use snforge_std::start_mock_call;
use utils::helpers::FromBytes;

Expand Down
Loading

0 comments on commit 682e099

Please sign in to comment.