Skip to content

Commit

Permalink
Merge pull request #527 from onflow/fix-estimate-gas-crasher
Browse files Browse the repository at this point in the history
Crasher on validation of args for `eth_estimateGas`
  • Loading branch information
sideninja authored Sep 6, 2024
2 parents 04ba8f7 + cb9f8a0 commit 5d58ddb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (txArgs TransactionArgs) Validate() error {
// e.g. https://github.com/onflow/go-ethereum/issues/16106.
if txDataLen == 0 {
// Prevent sending ether into black hole (show stopper)
if txArgs.Value.ToInt().Cmp(big.NewInt(0)) > 0 {
if txArgs.Value != nil && txArgs.Value.ToInt().Cmp(big.NewInt(0)) > 0 {
return errs.NewInvalidTransactionError(
errors.New("transaction will create a contract with value but empty code"),
)
Expand Down
12 changes: 12 additions & 0 deletions api/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ func TestValidateTransaction(t *testing.T) {
valid: false,
errMsg: "transaction will create a contract with empty code",
},
"create empty contract (nil value)": {
txArgs: TransactionArgs{
Nonce: (*hexutil.Uint64)(&nonce),
To: nil,
Value: nil,
Gas: (*hexutil.Uint64)(&gasLimit),
GasPrice: (*hexutil.Big)(big.NewInt(0)),
Data: &hexutil.Bytes{},
},
valid: false,
errMsg: "transaction will create a contract with empty code",
},
"create empty contract (with value)": {
txArgs: TransactionArgs{
Nonce: (*hexutil.Uint64)(&nonce),
Expand Down
14 changes: 14 additions & 0 deletions models/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,20 @@ func TestValidateTransaction(t *testing.T) {
valid: false,
errMsg: "transaction will create a contract with empty code",
},
"create empty contract (nil value)": {
tx: gethTypes.NewTx(
&gethTypes.LegacyTx{
Nonce: 1,
To: nil,
Value: nil,
Gas: 53_000,
GasPrice: big.NewInt(0),
Data: []byte{},
},
),
valid: false,
errMsg: "transaction will create a contract with empty code",
},
"create empty contract (with value)": {
tx: gethTypes.NewTx(
&gethTypes.LegacyTx{
Expand Down

0 comments on commit 5d58ddb

Please sign in to comment.