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

fix: create collision state #959

Merged
merged 1 commit into from
Sep 18, 2024
Merged
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 crates/evm/src/backend/starknet_backend.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn deploy(evm_address: EthAddress) -> Result<Address, EVMError> {
// Unlike CAs, there is not check for the existence of an EOA prealably to calling
// `EOATrait::deploy` - therefore, we need to check that there is no collision.
let mut is_deployed = evm_address.is_deployed();
ensure(!is_deployed, EVMError::DeployError(EOA_EXISTS))?;
ensure(!is_deployed, EVMError::Collision)?;

let mut kakarot_state = KakarotCore::unsafe_new_contract_state();
let uninitialized_account_class_hash = kakarot_state.uninitialized_account_class_hash();
Expand Down
4 changes: 2 additions & 2 deletions crates/evm/src/errors.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum EVMError {
InvalidParameter: felt252,
InvalidOpcode: u8,
WriteInStaticContext,
DeployError: felt252,
Collision,
OutOfGas,
Assertion,
DepthLimit,
Expand All @@ -78,7 +78,7 @@ pub impl EVMErrorImpl of EVMErrorTrait {
// TODO: refactor with dynamic strings once supported
EVMError::InvalidOpcode => 'invalid opcode'.into(),
EVMError::WriteInStaticContext => 'write protection',
EVMError::DeployError(error_message) => error_message,
EVMError::Collision => 'create collision'.into(),
EVMError::OutOfGas => 'out of gas'.into(),
EVMError::Assertion => 'assertion failed'.into(),
EVMError::DepthLimit => 'max call depth exceeded'.into(),
Expand Down
16 changes: 10 additions & 6 deletions crates/evm/src/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ use evm::instructions::{
use evm::model::account::{Account, AccountTrait};
use evm::model::vm::{VM, VMTrait};
use evm::model::{
Message, Environment, Transfer, ExecutionSummary, ExecutionSummaryTrait, ExecutionResult,
ExecutionResultTrait, ExecutionResultStatus, AddressTrait, TransactionResult, Address
Message, Environment, Transfer, ExecutionSummary, ExecutionResult, ExecutionResultTrait,
ExecutionResultStatus, AddressTrait, TransactionResult, Address
};
use evm::precompiles::Precompiles;
use evm::precompiles::eth_precompile_addresses;
Expand Down Expand Up @@ -170,7 +170,7 @@ pub impl EVMImpl of EVMTrait {
// };

TransactionResult {
success: summary.is_success(),
success: summary.status == ExecutionResultStatus::Success,
return_data: summary.return_data,
gas_used: total_gas_used,
state: summary.state,
Expand All @@ -185,9 +185,13 @@ pub impl EVMImpl of EVMTrait {
let result = if is_deploy_tx {
// Check collision
if target_account.has_code_or_nonce() {
return ExecutionSummaryTrait::exceptional_failure(
EVMError::DeployError(CONTRACT_ACCOUNT_EXISTS).to_bytes(),
);
return ExecutionSummary {
status: ExecutionResultStatus::Exception,
return_data: EVMError::Collision.to_bytes(),
gas_left: 0,
state: env.state,
gas_refund: 0
};
}

let mut result = Self::process_create_message(message, ref env);
Expand Down
24 changes: 0 additions & 24 deletions crates/evm/src/model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -108,30 +108,6 @@ pub struct ExecutionSummary {
pub gas_refund: u64
}

#[generate_trait]
pub impl ExecutionSummaryImpl of ExecutionSummaryTrait {
fn exceptional_failure(error: Span<u8>) -> ExecutionSummary {
ExecutionSummary {
status: ExecutionResultStatus::Exception,
return_data: error,
gas_left: 0,
state: Default::default(),
gas_refund: 0
}
}

fn is_success(self: @ExecutionSummary) -> bool {
*self.status == ExecutionResultStatus::Success
}

fn is_exception(self: @ExecutionSummary) -> bool {
*self.status == ExecutionResultStatus::Exception
}

fn is_revert(self: @ExecutionSummary) -> bool {
*self.status == ExecutionResultStatus::Revert
}
}

pub struct TransactionResult {
pub success: bool,
Expand Down
Loading