Skip to content
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

rpc/types: CheckTxFee should catch non-positive values and return an error #2414

Closed
1 task done
odeke-em opened this issue Mar 14, 2024 · 3 comments
Closed
1 task done

Comments

@odeke-em
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

This code doesn't return an error

package types

import (
	"math/big"
	"testing"
)

func TestCheckTxInvalids(t *testing.T) {
	gp := big.NewInt(-1)
	if err := CheckTxFee(gp, 10, 100); err == nil {
		t.Fatal("expecting a non-nil error")
	}
}

Evmos Version

main

How to reproduce?

Please run my reproduction

Fix

diff --git a/rpc/types/utils.go b/rpc/types/utils.go
index 964d1dcc..5270c5ad 100644
--- a/rpc/types/utils.go
+++ b/rpc/types/utils.go
@@ -4,6 +4,7 @@ package types
 
 import (
 	"context"
+	"errors"
 	"fmt"
 	"math/big"
 	"strings"
@@ -253,6 +254,9 @@ func CheckTxFee(gasPrice *big.Int, gas uint64, cap float64) error {
 	if cap == 0 {
 		return nil
 	}
+	if gasPrice.Sign() != 1 {
+		return errors.New("gasPrice must be positive!")
+	}
 	totalfee := new(big.Float).SetInt(new(big.Int).Mul(gasPrice, new(big.Int).SetUint64(gas)))
 	// 1 evmos in 10^18 aevmos
 	oneToken := new(big.Float).SetInt(big.NewInt(params.Ether))

/cc @fedekunze

Copy link

linear bot commented Mar 14, 2024

odeke-em added a commit to orijtech/evmos that referenced this issue Mar 14, 2024
This change catches invalid values in CheckTxFee
and returns an error for:
* nil gasPrice
* negative gasPrice

which improves the reliability of the system.

Fixes evmos#2413
Fixes evmos#2414
odeke-em added a commit to orijtech/evmos that referenced this issue Mar 14, 2024
This change catches invalid values in CheckTxFee
and returns an error for:
* nil gasPrice
* negative gasPrice

which improves the reliability of the system.

Fixes evmos#2413
Fixes evmos#2414
@odeke-em
Copy link
Contributor Author

Actually this looks like the absence of the enforcement that I raised is a major violation of the Ethereum specification per https://ethereum.github.io/yellowpaper/paper.pdf image

@MalteHerrmann
Copy link
Contributor

Closing this as per the comment on the linked PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants