Skip to content

Commit

Permalink
Fix eth invoke zero payments (#921)
Browse files Browse the repository at this point in the history
* Checks on zero payments added to eth invoke transaction.

* Activate invoke zero payments check after height from settings.
  • Loading branch information
alexeykiselev authored Oct 19, 2022
1 parent 9c21ffc commit 4ea0b32
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/settings/blockchain_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type FunctionalitySettings struct {
MinimalGeneratingBalanceCheckAfterTime uint64 `json:"minimal_generating_balance_check_after_time"`
InternalInvokePaymentsValidationAfterHeight uint64 `json:"internal_invoke_payments_validation_after_height"`
InternalInvokeCorrectFailRejectBehaviourAfterHeight uint64 `json:"internal_invoke_correct_fail_reject_behaviour_after_height"`
InvokeNoZeroPaymentsAfterHeight uint64 `json:"invoke_no_zero_payments_after_height"`

// Diff in milliseconds.
MaxTxTimeBackOffset uint64 `json:"max_tx_time_back_offset"`
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/embedded/mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"minimal_generating_balance_check_after_time": 1479168000000,
"internal_invoke_payments_validation_after_height": 2959400,
"internal_invoke_correct_fail_reject_behaviour_after_height": 2792473,
"invoke_no_zero_payments_after_height": 0,
"max_tx_time_back_offset": 7200000,
"max_tx_time_forward_offset": 5400000,
"address_scheme_character": 87,
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/embedded/stagenet.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"minimal_generating_balance_check_after_time": 0,
"internal_invoke_payments_validation_after_height": 966180,
"internal_invoke_correct_fail_reject_behaviour_after_height": 390000,
"invoke_no_zero_payments_after_height": 1317000,
"max_tx_time_back_offset": 7200000,
"max_tx_time_forward_offset": 5400000,
"address_scheme_character": 83,
Expand Down
1 change: 1 addition & 0 deletions pkg/settings/embedded/testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"minimal_generating_balance_check_after_time": 0,
"internal_invoke_payments_validation_after_height": 1698800,
"internal_invoke_correct_fail_reject_behaviour_after_height": 1727461,
"invoke_no_zero_payments_after_height": 0,
"max_tx_time_back_offset": 7200000,
"max_tx_time_forward_offset": 5400000,
"address_scheme_character": 84,
Expand Down
3 changes: 3 additions & 0 deletions pkg/state/script_caller.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ func (a *scriptCaller) invokeFunction(tree *ast.Tree, tx proto.Transaction, info
abiPayments := transaction.TxKind.DecodedData().Payments
scriptPayments := make([]proto.ScriptPayment, 0, len(abiPayments))
for _, p := range abiPayments {
if p.Amount <= 0 && info.checkerInfo.height > a.settings.InvokeNoZeroPaymentsAfterHeight {
return nil, errors.Errorf("invalid payment amount '%d'", p.Amount)
}
optAsset := proto.NewOptionalAsset(p.PresentAssetID, p.AssetID)
scriptPayment := proto.ScriptPayment{Amount: uint64(p.Amount), Asset: optAsset}
scriptPayments = append(scriptPayments, scriptPayment)
Expand Down
3 changes: 3 additions & 0 deletions pkg/state/transaction_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,9 @@ func (tc *transactionChecker) checkEthereumTransactionWithProofs(transaction pro

paymentAssets := make([]proto.OptionalAsset, 0, len(abiPayments))
for _, p := range abiPayments {
if p.Amount <= 0 && info.height > tc.settings.InvokeNoZeroPaymentsAfterHeight {
return nil, errors.Errorf("invalid payment amount '%d'", p.Amount)
}
optAsset := proto.NewOptionalAsset(p.PresentAssetID, p.AssetID)
if optAsset.Present {
if err := tc.checkAsset(&optAsset); err != nil {
Expand Down

0 comments on commit 4ea0b32

Please sign in to comment.