Skip to content

Commit 04c4cbc

Browse files
committed
fix: use params.Rules for core.IntrinsicGas() args
1 parent 81c80a8 commit 04c4cbc

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

libevm/precompiles/parallel/parallel.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/ava-labs/libevm/core"
2727
"github.com/ava-labs/libevm/core/types"
2828
"github.com/ava-labs/libevm/core/vm"
29+
"github.com/ava-labs/libevm/params"
2930
)
3031

3132
// A Handler is responsible for processing [types.Transactions] in an
@@ -106,7 +107,7 @@ func (p *Processor[R]) Close() {
106107
// StartBlock dispatches transactions to the [Handler] and returns immediately.
107108
// It MUST be paired with a call to [Processor.FinishBlock], without overlap of
108109
// blocks.
109-
func (p *Processor[R]) StartBlock(b *types.Block) error {
110+
func (p *Processor[R]) StartBlock(b *types.Block, rules params.Rules) error {
110111
txs := b.Transactions()
111112
jobs := make([]*job, 0, len(txs))
112113

@@ -117,7 +118,7 @@ func (p *Processor[R]) StartBlock(b *types.Block) error {
117118
}
118119

119120
for i, tx := range txs {
120-
switch do, err := p.shouldProcess(tx); {
121+
switch do, err := p.shouldProcess(tx, rules); {
121122
case err != nil:
122123
return err
123124

@@ -184,7 +185,7 @@ func (p *Processor[R]) Result(i int) (R, bool) {
184185
return *r.val, true
185186
}
186187

187-
func (p *Processor[R]) shouldProcess(tx *types.Transaction) (ok bool, err error) {
188+
func (p *Processor[R]) shouldProcess(tx *types.Transaction, rules params.Rules) (ok bool, err error) {
188189
cost, ok := p.handler.Gas(tx)
189190
if !ok {
190191
return false, nil
@@ -199,9 +200,9 @@ func (p *Processor[R]) shouldProcess(tx *types.Transaction) (ok bool, err error)
199200
tx.Data(),
200201
tx.AccessList(),
201202
tx.To() == nil,
202-
true, // Homestead
203-
true, // EIP-2028 (Istanbul)
204-
true, // EIP-3860 (Shanghai)
203+
rules.IsHomestead,
204+
rules.IsIstanbul, // EIP-2028
205+
rules.IsShanghai, // EIP-3860
205206
)
206207
if err != nil {
207208
return false, fmt.Errorf("calculating intrinsic gas of %v: %v", tx.Hash(), err)

libevm/precompiles/parallel/parallel_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestProcessor(t *testing.T) {
7777

7878
// Each set of params is effectively a test case, but they are all run on
7979
// the same [Processor].
80-
params := []blockParams{
80+
tests := []blockParams{
8181
{
8282
numTxs: 0,
8383
},
@@ -108,39 +108,40 @@ func TestProcessor(t *testing.T) {
108108

109109
rng := rand.New(rand.NewPCG(0, 0)) //nolint:gosec // Reproducibility is useful for testing
110110
for range 100 {
111-
params = append(params, blockParams{
111+
tests = append(tests, blockParams{
112112
numTxs: rng.IntN(1000),
113113
sendToAddrEvery: 1 + rng.IntN(30),
114114
sufficientGasEvery: 1 + rng.IntN(30),
115115
})
116116
}
117117

118-
for _, tc := range params {
118+
for _, tt := range tests {
119119
t.Run("", func(t *testing.T) {
120-
t.Logf("%+v", tc)
120+
t.Logf("%+v", tt)
121121

122-
txs := make(types.Transactions, tc.numTxs)
123-
wantProcessed := make([]bool, tc.numTxs)
122+
var rules params.Rules
123+
txs := make(types.Transactions, tt.numTxs)
124+
wantProcessed := make([]bool, tt.numTxs)
124125
for i := range len(txs) {
125126
var (
126127
to common.Address
127128
extraGas uint64
128129
)
129130

130131
wantProcessed[i] = true
131-
if i%tc.sendToAddrEvery == 0 {
132+
if i%tt.sendToAddrEvery == 0 {
132133
to = handler.addr
133134
} else {
134135
wantProcessed[i] = false
135136
}
136-
if i%tc.sufficientGasEvery == 0 {
137+
if i%tt.sufficientGasEvery == 0 {
137138
extraGas = handler.gas
138139
} else {
139140
wantProcessed[i] = false
140141
}
141142

142143
data := binary.BigEndian.AppendUint64(nil, uint64(i))
143-
gas, err := core.IntrinsicGas(data, nil, false, true, true, true)
144+
gas, err := core.IntrinsicGas(data, nil, false, rules.IsHomestead, rules.IsIstanbul, rules.IsShanghai)
144145
require.NoError(t, err, "core.IntrinsicGas(%#x, nil, false, true, true, true)", data)
145146

146147
txs[i] = types.NewTx(&types.LegacyTx{
@@ -151,7 +152,7 @@ func TestProcessor(t *testing.T) {
151152
}
152153

153154
block := types.NewBlock(&types.Header{}, txs, nil, nil, trie.NewStackTrie(nil))
154-
require.NoError(t, p.StartBlock(block), "BeforeBlock()")
155+
require.NoError(t, p.StartBlock(block, rules), "StartBlock()")
155156
defer p.FinishBlock(block)
156157

157158
for i, tx := range txs {
@@ -285,7 +286,8 @@ func TestIntegration(t *testing.T) {
285286
}
286287

287288
block := types.NewBlock(&types.Header{}, txs, nil, nil, trie.NewStackTrie(nil))
288-
require.NoError(t, sut.StartBlock(block), "StartBlock()")
289+
rules := evm.ChainConfig().Rules(block.Number(), true, block.Time())
290+
require.NoError(t, sut.StartBlock(block, rules), "StartBlock()")
289291
defer sut.FinishBlock(block)
290292

291293
pool := core.GasPool(math.MaxUint64)

0 commit comments

Comments
 (0)