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

feat: mark accounts created in a tx as created #789

Merged
merged 2 commits into from
Apr 24, 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
3 changes: 3 additions & 0 deletions crates/evm/src/interpreter.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ impl EVMImpl of EVMTrait {
EVMError::DeployError(CONTRACT_ACCOUNT_EXISTS).to_bytes(),
);
}

let mut result = EVMTrait::process_create_message(message, ref env);
if result.success {
result.return_data = message.target.evm.to_bytes().span();
Expand Down Expand Up @@ -65,6 +66,8 @@ impl EVMImpl of EVMTrait {

// Increment nonce of target
target_account.set_nonce(1);
// Set the target as created
target_account.set_created(true);
target_account.address = message.target;
env.state.set_account(target_account);

Expand Down
11 changes: 9 additions & 2 deletions crates/evm/src/model/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ impl AccountBuilderImpl of AccountBuilderTrait {
nonce: 0,
balance: 0,
selfdestruct: false,
is_created: false
}
}
}
Expand Down Expand Up @@ -65,14 +66,14 @@ impl AccountBuilderImpl of AccountBuilderTrait {
}
}


#[derive(Copy, Drop, PartialEq)]
struct Account {
address: Address,
code: Span<u8>,
nonce: u64,
balance: u256,
selfdestruct: bool,
is_created: bool,
}

#[generate_trait]
Expand Down Expand Up @@ -137,8 +138,14 @@ impl AccountImpl of AccountTrait {
return !(*self.code).is_empty() || *self.nonce != 0;
}

#[inline(always)]
fn is_created(self: @Account) -> bool {
panic!("unimplemented is created")
*self.is_created
}

#[inline(always)]
fn set_created(ref self: Account, is_created: bool) {
self.is_created = is_created;
}

#[inline(always)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ fn test_exec_sload_from_storage() {
code: array![0xab, 0xcd, 0xef].span(),
nonce: 1,
balance: 0,
selfdestruct: false
selfdestruct: false,
is_created: false,
};
let key: u256 = 0x100000000000000000000000000000001;
let value: u256 = 0xABDE1E11A5;
Expand Down Expand Up @@ -586,7 +587,8 @@ fn test_exec_sstore_on_contract_account_alive() {
code: array![].span(),
nonce: 1,
balance: 0,
selfdestruct: false
selfdestruct: false,
is_created: false,
};
vm.env.state.set_account(account);
assert!(vm.env.state.is_account_alive(account.address.evm));
Expand Down Expand Up @@ -626,7 +628,12 @@ fn test_exec_sstore_finalized() {
// Deploys the contract account to be able to commit storage changes.
let ca_address = deploy_contract_account(vm.message().target.evm, array![].span());
let account = Account {
address: ca_address, code: array![].span(), nonce: 1, balance: 0, selfdestruct: false
address: ca_address,
code: array![].span(),
nonce: 1,
balance: 0,
selfdestruct: false,
is_created: false,
};
let key: u256 = 0x100000000000000000000000000000001;
let value: u256 = 0xABDE1E11A5;
Expand Down
1 change: 1 addition & 0 deletions crates/evm/src/tests/test_model.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ fn test_account_commit_undeployed() {
code: array![0x69].span(),
balance: 0,
selfdestruct: false,
is_created: false,
};
account.nonce = 420;
account.code = array![0x1].span();
Expand Down
12 changes: 8 additions & 4 deletions crates/evm/src/tests/test_state.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ mod test_state {
code: Default::default().span(),
nonce: 0,
balance: 0,
selfdestruct: false
selfdestruct: false,
is_created: false,
};

let account = state.get_account(evm_address);
Expand All @@ -125,7 +126,8 @@ mod test_state {
code: array![0xab, 0xcd, 0xef].span(),
nonce: 1,
balance: 420,
selfdestruct: false
selfdestruct: false,
is_created: false,
};

state.set_account(expected_account);
Expand Down Expand Up @@ -153,7 +155,8 @@ mod test_state {
code: array![0xab, 0xcd, 0xef].span(),
nonce: 1,
balance: 420,
selfdestruct: false
selfdestruct: false,
is_created: false,
};

let account = state.get_account(evm_address);
Expand Down Expand Up @@ -190,7 +193,8 @@ mod test_state {
code: array![0xab, 0xcd, 0xef].span(),
nonce: 1,
balance: 0,
selfdestruct: false
selfdestruct: false,
is_created: false,
};
IAccountDispatcher { contract_address: account.starknet_address() }
.write_storage(key, value);
Expand Down
3 changes: 2 additions & 1 deletion crates/evm/src/tests/test_utils.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,8 @@ fn initialize_contract_account(
code: array![0xab, 0xcd, 0xef].span(),
nonce: 1,
balance: 0,
selfdestruct: false
selfdestruct: false,
is_created: false,
};
let mut i = 0;
loop {
Expand Down
Loading