-
Notifications
You must be signed in to change notification settings - Fork 647
Eth call variants #3824
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
Closed
Closed
Eth call variants #3824
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8360b1c
Support various eth_call invocations.
kjazgar 1f1f972
Added some test cases.
kjazgar 3d82078
Added error handling.
kjazgar 10870a9
Fixed insufficient sender balance exception handling.
kjazgar 1d069b7
Fixed insufficient sender balance exception handling.
kjazgar 9afc09d
Fixed tests.
kjazgar 93b6837
Fixed test.
kjazgar 29a9f7f
Refactored code.
kjazgar 5bb1116
Refactored code.
kjazgar fe294ca
Merge branch 'master' into eth_call_variants
kjazgar 15b4898
Refactored code.
kjazgar 950ed37
Used clone of config instead of changing global one.
kjazgar f22579f
Refactored code.
kjazgar 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,7 +67,12 @@ private enum ExecutionOptions | |
| /// <summary> | ||
| /// Commit and later restore state also skip validation, use for CallAndRestore | ||
| /// </summary> | ||
| CommitAndRestore = Commit | Restore | NoValidation | ||
| CommitAndRestore = Commit | Restore | NoValidation, | ||
|
|
||
| /// <summary> | ||
| /// Commit and later restore state also skip base fee validation if gas pricing is not passed | ||
| /// </summary> | ||
| NoBaseFee = CommitAndRestore | 8 | ||
| } | ||
|
|
||
| public TransactionProcessor( | ||
|
|
@@ -116,6 +121,11 @@ public void Trace(Transaction transaction, BlockHeader block, ITxTracer txTracer | |
| Execute(transaction, block, txTracer, ExecutionOptions.NoValidation); | ||
| } | ||
|
|
||
| public void CallWithNoBaseFee(Transaction transaction, BlockHeader block, ITxTracer txTracer) | ||
| { | ||
| Execute(transaction, block, txTracer, ExecutionOptions.NoBaseFee); | ||
| } | ||
|
|
||
| private void QuickFail(Transaction tx, BlockHeader block, ITxTracer txTracer, bool eip658NotEnabled, | ||
| string? reason) | ||
| { | ||
|
|
@@ -138,6 +148,19 @@ private void QuickFail(Transaction tx, BlockHeader block, ITxTracer txTracer, bo | |
| } | ||
| } | ||
|
|
||
| private bool ShouldSkipGasPricing(IReleaseSpec spec, Transaction transaction) | ||
| { | ||
| if (!spec.IsEip1559Enabled) return transaction.GasPrice.IsZero; | ||
|
|
||
| if (transaction.IsEip1559) | ||
| { | ||
| return transaction.MaxFeePerGas.IsZero && transaction.MaxPriorityFeePerGas.IsZero; | ||
| } | ||
|
|
||
| return transaction.GasPrice.IsZero; | ||
|
|
||
| } | ||
|
|
||
| private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTracer, | ||
| ExecutionOptions executionOptions) | ||
| { | ||
|
|
@@ -152,15 +175,38 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra | |
| //we commit only after all block is constructed | ||
| bool notSystemTransaction = !transaction.IsSystem(); | ||
| bool deleteCallerAccount = false; | ||
| bool noBaseFee = (executionOptions & ExecutionOptions.NoBaseFee) == ExecutionOptions.NoBaseFee; | ||
| bool validatePricing = !noValidation || noBaseFee; | ||
|
|
||
| IReleaseSpec spec = _specProvider.GetSpec(block.Number); | ||
| if (!notSystemTransaction) | ||
| { | ||
| spec = new SystemTransactionReleaseSpec(spec); | ||
| } | ||
|
|
||
| bool skipGasPricing = ShouldSkipGasPricing(spec, transaction); | ||
|
|
||
| UInt256 value = transaction.Value; | ||
|
|
||
| if (!noBaseFee || transaction.MaxFeePerGas > 0 || transaction.MaxPriorityFeePerGas > 0) | ||
| { | ||
| if (validatePricing && transaction.MaxFeePerGas < block.BaseFeePerGas) | ||
| { | ||
| TraceLogInvalidTx(transaction, "MAX FEE PER GAS LESS THAN BLOCK BASE FEE"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, | ||
| $"max fee per gas less than block base fee: address {transaction.SenderAddress}, maxFeePerGas: {transaction.MaxFeePerGas}, baseFee {block.BaseFeePerGas}"); | ||
| return; | ||
| } | ||
|
|
||
| if (validatePricing && transaction.MaxFeePerGas < transaction.MaxPriorityFeePerGas) | ||
| { | ||
| TraceLogInvalidTx(transaction, "MAX FEE PER GAS LESS THAN MAX PRIORITY FEE PER GAS"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, | ||
| $"max fee per gas less than max priority fee per gas: address {transaction.SenderAddress}, maxFeePerGas: {transaction.MaxFeePerGas}, maxPriorityFeePerGas: {transaction.MaxPriorityFeePerGas}"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (!transaction.TryCalculatePremiumPerGas(block.BaseFeePerGas, out UInt256 premiumPerGas) && !noValidation) | ||
| { | ||
| TraceLogInvalidTx(transaction, "MINER_PREMIUM_IS_NEGATIVE"); | ||
|
|
@@ -200,15 +246,15 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra | |
| if (gasLimit < intrinsicGas) | ||
| { | ||
| TraceLogInvalidTx(transaction, $"GAS_LIMIT_BELOW_INTRINSIC_GAS {gasLimit} < {intrinsicGas}"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, "gas limit below intrinsic gas"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, $"gas limit below intrinsic gas: have {gasLimit}, want {intrinsicGas}"); | ||
| return; | ||
| } | ||
|
|
||
| if (!noValidation && gasLimit > block.GasLimit - block.GasUsed) | ||
| { | ||
| TraceLogInvalidTx(transaction, | ||
| $"BLOCK_GAS_LIMIT_EXCEEDED {gasLimit} > {block.GasLimit} - {block.GasUsed}"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, "block gas limit exceeded"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, $"block gas limit exceeded: gasLimit {gasLimit} > block gasLimit {block.GasLimit} - block gasUsed {block.GasUsed}"); | ||
| return; | ||
| } | ||
| } | ||
|
|
@@ -249,24 +295,26 @@ private void Execute(Transaction transaction, BlockHeader block, ITxTracer txTra | |
|
|
||
| if (notSystemTransaction) | ||
| { | ||
| UInt256 senderBalance = _stateProvider.GetBalance(caller); | ||
| if (!noValidation && ((ulong)intrinsicGas * effectiveGasPrice + value > senderBalance || | ||
| senderReservedGasPayment + value > senderBalance)) | ||
| if (!noBaseFee || !skipGasPricing) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. meaningful labels for bool checks |
||
| { | ||
| TraceLogInvalidTx(transaction, | ||
| $"INSUFFICIENT_SENDER_BALANCE: ({caller})_BALANCE = {senderBalance}"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, "insufficient sender balance"); | ||
| return; | ||
| } | ||
| UInt256 senderBalance = _stateProvider.GetBalance(caller); | ||
| if (validatePricing && ((ulong)intrinsicGas * effectiveGasPrice + value > senderBalance || | ||
| senderReservedGasPayment + value > senderBalance)) | ||
| { | ||
| TraceLogInvalidTx(transaction, | ||
| $"INSUFFICIENT_SENDER_BALANCE: ({caller})_BALANCE = {senderBalance}"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, $"insufficient funds for gas * price + value: address {caller}, have {senderBalance}, want {UInt256.Max(senderReservedGasPayment + value, (ulong)intrinsicGas * effectiveGasPrice + value)}"); | ||
| return; | ||
| } | ||
|
|
||
| if (!noValidation && spec.IsEip1559Enabled && !transaction.IsFree() && | ||
| senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + value) | ||
| { | ||
| TraceLogInvalidTx(transaction, | ||
| $"INSUFFICIENT_MAX_FEE_PER_GAS_FOR_SENDER_BALANCE: ({caller})_BALANCE = {senderBalance}, MAX_FEE_PER_GAS: {transaction.MaxFeePerGas}"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, | ||
| "insufficient MaxFeePerGas for sender balance"); | ||
| return; | ||
| if (validatePricing && spec.IsEip1559Enabled && !transaction.IsFree() && | ||
| senderBalance < (UInt256)transaction.GasLimit * transaction.MaxFeePerGas + value) | ||
| { | ||
| TraceLogInvalidTx(transaction, | ||
| $"INSUFFICIENT_MAX_FEE_PER_GAS_FOR_SENDER_BALANCE: ({caller})_BALANCE = {senderBalance}, MAX_FEE_PER_GAS: {transaction.MaxFeePerGas}"); | ||
| QuickFail(transaction, block, txTracer, eip658NotEnabled, $"insufficient MaxFeePerGas for sender balance: address {{caller}}, sender_balance = {senderBalance}, maxFeePerGas: {transaction.MaxFeePerGas}"); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| if (transaction.Nonce != _stateProvider.GetNonce(caller)) | ||
|
|
||
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.
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.
meaningful labels for bool checks