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

Commit

Permalink
Deploy account only if it has code or nonce
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementWalter committed Nov 7, 2023
1 parent 4277d5f commit 527da5d
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/kakarot/account.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,27 @@ namespace Account {
return ();
}

// Deploy accounts
let (class_hash) = contract_account_class_hash.read();
deploy(class_hash, self.address);
// Write bytecode
IContractAccount.write_bytecode(starknet_address, self.code_len, self.code);
// Set nonce
IContractAccount.set_nonce(starknet_address, self.nonce);
// Save storages
Internals._save_storage(starknet_address, self.storage_start, self.storage);
return ();
// Just casting the Summary into an Account to apply has_code_or_nonce
// cf Summary note: like an Account, but frozen after squashing all dicts
// There is no reason to have has_code_or_nonce available in the public API
// for Account.Summary, but safe to use here
let code_or_nonce = has_code_or_nonce(cast(self, model.Account*));

Check warning on line 132 in src/kakarot/account.cairo

View check run for this annotation

Codecov / codecov/patch

src/kakarot/account.cairo#L132

Added line #L132 was not covered by tests

if (code_or_nonce != FALSE) {

Check warning on line 134 in src/kakarot/account.cairo

View check run for this annotation

Codecov / codecov/patch

src/kakarot/account.cairo#L134

Added line #L134 was not covered by tests
// Deploy accounts
let (class_hash) = contract_account_class_hash.read();
deploy(class_hash, self.address);

Check warning on line 137 in src/kakarot/account.cairo

View check run for this annotation

Codecov / codecov/patch

src/kakarot/account.cairo#L136-L137

Added lines #L136 - L137 were not covered by tests
// Write bytecode
IContractAccount.write_bytecode(starknet_address, self.code_len, self.code);

Check warning on line 139 in src/kakarot/account.cairo

View check run for this annotation

Codecov / codecov/patch

src/kakarot/account.cairo#L139

Added line #L139 was not covered by tests
// Set nonce
IContractAccount.set_nonce(starknet_address, self.nonce);

Check warning on line 141 in src/kakarot/account.cairo

View check run for this annotation

Codecov / codecov/patch

src/kakarot/account.cairo#L141

Added line #L141 was not covered by tests
// Save storages
Internals._save_storage(starknet_address, self.storage_start, self.storage);
return ();

Check warning on line 144 in src/kakarot/account.cairo

View check run for this annotation

Codecov / codecov/patch

src/kakarot/account.cairo#L143-L144

Added lines #L143 - L144 were not covered by tests
} else {
// Touched an undeployed address in a CALL, do nothing
return ();

Check warning on line 147 in src/kakarot/account.cairo

View check run for this annotation

Codecov / codecov/patch

src/kakarot/account.cairo#L147

Added line #L147 was not covered by tests
}
}

// Case existing Account and SELFDESTRUCT
Expand Down

0 comments on commit 527da5d

Please sign in to comment.