Skip to content

Commit

Permalink
Dont reduce precision when estimating gas for eth transfers (0xPolygo…
Browse files Browse the repository at this point in the history
…nHermez#1249)

* Dont reduce preciosion when estimating gas for eth transfers

* Dont reduce preciosion when estimating gas for eth transfers

* check if transaction.To() is a SC

* check if transaction.To() is a SC

* check if transaction.To() is a SC
  • Loading branch information
ToniRamirezM authored Oct 10, 2022
1 parent 7571ca2 commit 696e887
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,11 @@ func (s *State) GetStorageAt(ctx context.Context, address common.Address, positi

// EstimateGas for a transaction
func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common.Address, l2BlockNumber *uint64, dbTx pgx.Tx) (uint64, error) {
const ethTransferGas = 21000

var lowEnd uint64
var highEnd uint64

ctx := context.Background()

lastBatches, l2BlockStateRoot, err := s.PostgresStorage.GetLastNBatchesByL2BlockNumber(ctx, l2BlockNumber, two, dbTx)
Expand All @@ -143,6 +146,15 @@ func (s *State) EstimateGas(transaction *types.Transaction, senderAddress common
return 0, err
}

if lowEnd == ethTransferGas && transaction.To() != nil {
code, err := s.tree.GetCode(ctx, *transaction.To(), l2BlockStateRoot.Bytes())
if err != nil {
log.Warnf("error while getting transaction.to() code %v", err)
} else if len(code) == 0 {
return lowEnd, nil
}
}

if transaction.Gas() != 0 && transaction.Gas() > lowEnd {
highEnd = transaction.Gas()
} else {
Expand Down

0 comments on commit 696e887

Please sign in to comment.