-
Notifications
You must be signed in to change notification settings - Fork 1.2k
revive: Fix dust & child contract calls #10192
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
Changes from 5 commits
77eda1a
cff6c37
948a809
a4f6970
fbcdeec
fac4618
0d74778
5b90b78
1d0d91d
959c7d2
3d0628b
b8bed4f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| title: 'revive: Fix dust & child contract calls' | ||
| doc: | ||
| - audience: Runtime Dev | ||
| description: |- | ||
| When transferring to self we should just return early as it's a noop. | ||
| Not doing so cause bug in `transfer_with_dust` | ||
|
|
||
| as we do | ||
| ``` | ||
| from.dust -= from.dust | ||
| to.dust += to.dust | ||
| ``` | ||
|
|
||
| We end up with a value of dust - planck (that we burnt from to create dust amount) on the account | ||
|
|
||
| fix https://github.com/paritytech/contract-issues/issues/211 | ||
| crates: | ||
| - name: pallet-revive-fixtures | ||
| bump: patch | ||
| - name: pallet-revive | ||
| bump: patch |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| contract CallSelfWithDust { | ||
| function f() external payable {} | ||
|
|
||
| function call() public payable { | ||
| this.f{value: 10}(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1521,6 +1521,10 @@ where | |
| storage_meter: &mut storage::meter::GenericMeter<T, S>, | ||
| exec_config: &ExecConfig<T>, | ||
| ) -> DispatchResult { | ||
| if from == to || value.is_zero() { | ||
|
||
| return Ok(()) | ||
| } | ||
|
|
||
| fn transfer_with_dust<T: Config>( | ||
| from: &AccountIdOf<T>, | ||
| to: &AccountIdOf<T>, | ||
|
|
||
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.
To check, if
fhere contained some code, this code will be executed and the only thing that we have aNOOPfor is just the transfers, is that correct?Uh oh!
There was an error while loading. Please reload this page.
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 this breaks the EVM semantics.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 we short-circuit the logic of the transfer_with_dust fn when from = to or value = 0 the rest does not change
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.
ah right we should always check that from.balance > amount is that what you are suggesting @xermicus
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.
Nevermind. I saw that there is already a zero balance check in the transfer function and short-circuited that this is implemented in logic further up.
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.
Current implementation is wrong i believe we should ensure that the account has enough balance to do the transfer even if to == from
Will patch it when i het back
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.
Yeah the logic is quite complex with dust. Maybe needs some more tests for these corner cases.