-
Notifications
You must be signed in to change notification settings - Fork 27
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(levm): create to an existing address #1523
Conversation
… transact(). Revert in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG(reat)TM
// transaction should be reverted. | ||
if self.is_create() { | ||
let new_address_acc = self.db.get_account_info(initial_call_frame.to); | ||
if new_address_acc.has_code() || new_address_acc.has_nonce() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: Should this be an ||
or a &&
?
If an ||
is needed, then I think a function already exists for it
if new_address_acc.has_code() || new_address_acc.has_nonce() { | |
if new_address_acc.has_code_or_nonce() { |
Having said that, I think the function itself is a bit overkill.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an ||
. We created the function because of the specs. It may be a little bit overkill but we can use it I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The type of new_address_acc
is AccountInfo
. This type doesn't have that method :( Maybe we can implement it in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is an
||
. We created the function because of the specs. It may be a little bit overkill but we can use it I guess.
Noted, thank you for the link Jere!
The type of
new_address_acc
isAccountInfo
. This type doesn't have that method :( Maybe we can implement it in the future.
Oh, my mistake Dami.
Co-authored-by: Tomas Fabrizio Orsi <tomas.orsi@lambdaclass.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good, left some suggestions. The "De Morgan" suggestion doesn't seem to improve code readability, I don't know why I suggested it haha
.checked_add(new_account.balance) | ||
.ok_or(VMError::BalanceOverflow)?; | ||
|
||
if !new_account.has_code() && !new_account.has_nonce() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if !new_account.has_code() && !new_account.has_nonce() { | |
if !new_account.has_code_or_nonce() { |
Thank you De Morgan (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to change it. Maybe it is more readable the original way haha
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes hahaha I think the first implementation is more readable.
Co-authored-by: Jeremías Salomón <48994069+JereSalo@users.noreply.github.com>
Co-authored-by: Jeremías Salomón <48994069+JereSalo@users.noreply.github.com>
Motivation
The
CREATE
transaction logic did not handle the case where the address where we the contract will be deploy already exists.Description
VM::new()
where the transaction isCREATE
. Ifnew_contract_address
exists in the db and it has nonce or bytecode, we don't create the new account and we don't add it in the cache. We know this is an error and the revert will be handled intransact()
transact()
, we check if the transaction isCREATE
and ifnew_address_acc
has code or nonce. In that case we return aTransactionReport
withTxResult::Revert
.Related #1517