-
Notifications
You must be signed in to change notification settings - Fork 1k
Exec Factor with decimals #4278
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
Open
shargon
wants to merge
5
commits into
neo-project:master
Choose a base branch
from
shargon:exec-fee-4-decimals
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+269
−186
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Right now both
GasConsumedandGasLeftare rounded to the upper integer. But this behaviour violatesGasConsumed+GasLeft=(_feeAmount / FeeFactor)condition (we know that_feeAmountis divisible byFeeFactorby definition).For
GasConsumedrounding to the upper integer is correct sinceGasConsumedis used for transaction's fee calculation and e.g. transaction'sSystemFeeshould cover sub-Datoshi execution cost.For
GasLeftI'm not sure what's the correct behaviour. Right nowGasLeftis used only bySystem.Runtime.GasLeftinterop, so rounding it to the upper value may be misleading for the smart contract (since in fact there's less gas remaining in the VM thanSystem.Runtime.GasLefttells). From another hand, roundingGasLeftto the lower integer may lead to the situation whenSystem.Runtime.GasLeftreturns 0 whereas some instructions still may be executed if we have some 0.999 GAS left in fact.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.
Here's the statistics of
System.Runtime.GasLeftinterop usage on Mainnet up to8179793height:200136calls of this interop up to the current heightFlamingoBrokercontractgeneratorcontract by CoZpuppetNEP-11 contract by CoZitemNEP-11 by CoZlizardNEP-11 by CoZotterNEP-11 by CoZVaultencontract, some on-chain puzzle gamepackageNEP-11 contract by CoZGhostMarketexchange contractSmartFLOCKSMintercontractHere's the full log with additional data on usage: link.
The most active contract is FlamingoBroker contract. Its source code is not public, but here's the usage scenario taken from the bytecode (this pattern is used multiple times in the contract):
System.Runtime.GasLeft usage in `FlamingoBroker` contract
So it looks like the overall usage pattern is "Burn some GAS until a specific amount of free GAS remains" (although we may ask @adrian-fjellberg or @odd86 for details). So @shargon, given this fact and the fact that it's related to trading, we assume that it's more safe to round
GasLeftto the lower integer instead of rounding to the upper integer. Because smart contract relays on fact that the specified amount of GAS is 100% available to spent it to some invocation.The second contract is generator contract deployed by CoZ, it has a little bit different pattern of usage:
System.Runtime.GasLeft usage in `generator` contract
And it looks like rounding
GasLeftto the lower integer doesn't hurt this pattern of usage as far.The third contract is puppet by CoZ, it also has a very similar pattern of usage which looks to me like: "burn the amount of GAS left after execution of some contract bytecode (with an adjustment)"
System.Runtime.GasLeft usage in `puppet` contract
And for this pattern rounding
GasLeftto the lower integer also doesn't hurt.I didn't check other contracts, but if needed, then I may analyze the usage pattern for the rest of the contracts and attach the results. @shargon, @roman-khimov, please let me know your thoughts on this.