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

Commit

Permalink
Commit account iif it has code or nonce (#802)
Browse files Browse the repository at this point in the history
Time spent on this PR: 0.1

## Pull request type

Please check the type of change your PR introduces:

- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, renaming)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] Documentation content changes
- [ ] Other (please describe):

## What is the current behavior?

When an account is not registered, it's deployed as a CA in `commit` in
any cases.

Resolves #793

## What is the new behavior?

A contract is deployed only if it has code or nonce.
  • Loading branch information
ClementWalter authored Nov 7, 2023
1 parent 4277d5f commit a396881
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*));

if (code_or_nonce != FALSE) {
// 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 ();
} else {
// Touched an undeployed address in a CALL, do nothing
return ();
}
}

// Case existing Account and SELFDESTRUCT
Expand Down

0 comments on commit a396881

Please sign in to comment.