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 doesn't check if gasPrice is nil #2413

Open
1 task done
odeke-em opened this issue Mar 14, 2024 · 1 comment
Open
1 task done

rpc/types: CheckTxFee doesn't check if gasPrice is nil #2413

odeke-em opened this issue Mar 14, 2024 · 1 comment

Comments

@odeke-em
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

While security auditing this code I noticed that this code doesn't return an error

package types                   

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

there should be an error returned

Evmos Version

main

How to reproduce?

Run the repro produced

Fix

diff --git a/rpc/types/utils.go b/rpc/types/utils.go
index 964d1dcc..0a6676f3 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 == nil {
+		return errors.New("gasPrice is nil")
+	}
 	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))
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
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.

1 participant