Skip to content

Commit b184ca5

Browse files
author
Darioush Jalali
authored
Merge branch 'master' into refactor-allow-unfinalized
2 parents 49b05b6 + 7832d53 commit b184ca5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+837
-1225
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
token: ${{ secrets.AVALANCHE_PAT }}
3232
- uses: actions/setup-go@v3
3333
with:
34-
go-version: '~1.20.10'
34+
go-version: '~1.20.12'
3535
check-latest: true
3636
- name: change avalanchego dep
3737
if: ${{ github.event_name == 'workflow_dispatch' }}
@@ -65,7 +65,7 @@ jobs:
6565
token: ${{ secrets.AVALANCHE_PAT }}
6666
- uses: actions/setup-go@v3
6767
with:
68-
go-version: '~1.20.10'
68+
go-version: '~1.20.12'
6969
check-latest: true
7070
- name: change avalanchego dep
7171
if: ${{ github.event_name == 'workflow_dispatch' }}
@@ -98,7 +98,7 @@ jobs:
9898
token: ${{ secrets.AVALANCHE_PAT }}
9999
- uses: actions/setup-go@v3
100100
with:
101-
go-version: '~1.20.10'
101+
go-version: '~1.20.12'
102102
check-latest: true
103103
- name: change avalanchego dep
104104
if: ${{ github.event_name == 'workflow_dispatch' }}
@@ -129,7 +129,7 @@ jobs:
129129
token: ${{ secrets.AVALANCHE_PAT }}
130130
- uses: actions/setup-go@v3
131131
with:
132-
go-version: '~1.20.10'
132+
go-version: '~1.20.12'
133133
check-latest: true
134134
- name: Run e2e tests
135135
run: E2E_SERIAL=1 ./scripts/tests.e2e.sh

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ============= Compilation Stage ================
2-
FROM golang:1.20.10-bullseye AS builder
2+
FROM golang:1.20.12-bullseye AS builder
33

44
ARG AVALANCHE_VERSION
55

accounts/abi/type.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
189189
return Type{}, errors.New("abi: purely anonymous or underscored field is not supported")
190190
}
191191
fieldName := ResolveNameConflict(name, func(s string) bool { return used[s] })
192-
if err != nil {
193-
return Type{}, err
194-
}
192+
195193
used[fieldName] = true
196194
if !isValidFieldName(fieldName) {
197195
return Type{}, fmt.Errorf("field %d has invalid name", idx)

consensus/dummy/consensus.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,13 @@ func (self *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, heade
187187

188188
// modified from consensus.go
189189
func (self *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *types.Header, parent *types.Header, uncle bool) error {
190-
var (
191-
config = chain.Config()
192-
)
190+
config := chain.Config()
193191
// Ensure that we do not verify an uncle
194192
if uncle {
195193
return errUnclesUnsupported
196194
}
197195
switch {
198-
case config.IsDUpgrade(header.Time):
196+
case config.IsDurango(header.Time):
199197
if len(header.Extra) < params.DynamicFeeExtraDataSize {
200198
return fmt.Errorf("expected extra-data field length >= %d, found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
201199
}
@@ -217,7 +215,7 @@ func (self *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header
217215
if header.Time > uint64(time.Now().Add(allowedFutureBlockTime).Unix()) {
218216
return consensus.ErrFutureBlock
219217
}
220-
//if header.Time <= parent.Time {
218+
// if header.Time <= parent.Time {
221219
if header.Time < parent.Time {
222220
return errInvalidBlockTime
223221
}
@@ -395,7 +393,8 @@ func (self *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *type
395393
}
396394

397395
func (self *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, parent *types.Header, state *state.StateDB, txs []*types.Transaction,
398-
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
396+
uncles []*types.Header, receipts []*types.Receipt,
397+
) (*types.Block, error) {
399398
var (
400399
contribution, extDataGasUsed *big.Int
401400
extraData []byte

core/blockchain.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,10 @@ type BlockChain struct {
230230

231231
stopping atomic.Bool // false if chain is running, true when stopped
232232

233-
engine consensus.Engine
234-
validator Validator // Block and state validator interface
235-
prefetcher Prefetcher // Block state prefetcher interface
236-
processor Processor // Block transaction processor interface
237-
vmConfig vm.Config
233+
engine consensus.Engine
234+
validator Validator // Block and state validator interface
235+
processor Processor // Block transaction processor interface
236+
vmConfig vm.Config
238237

239238
lastAccepted *types.Block // Prevents reorgs past this height
240239

@@ -335,7 +334,6 @@ func NewBlockChain(
335334
}
336335
bc.stateCache = state.NewDatabaseWithNodeDB(bc.db, bc.triedb)
337336
bc.validator = NewBlockValidator(chainConfig, bc, engine)
338-
bc.prefetcher = newStatePrefetcher(chainConfig, bc, engine)
339337
bc.processor = NewStateProcessor(chainConfig, bc, engine)
340338

341339
bc.hc, err = NewHeaderChain(db, chainConfig, cacheConfig, engine)
@@ -1321,8 +1319,6 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
13211319
statedb.StartPrefetcher("chain", bc.cacheConfig.TriePrefetcherParallelism)
13221320
activeState = statedb
13231321

1324-
// If we have a followup block, run that against the current state to pre-cache
1325-
// transactions and probabilistically some of the account/storage trie nodes.
13261322
// Process block using the parent state as reference point
13271323
pstart := time.Now()
13281324
receipts, logs, usedGas, err := bc.processor.Process(block, parent, statedb, bc.vmConfig)

core/evm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
5454
if !ok {
5555
return newEVMBlockContext(header, chain, author, nil)
5656
}
57-
// Prior to the DUpgrade, the VM enforces the extra data is smaller than or
58-
// equal to this size. After the DUpgrade, the VM pre-verifies the extra
57+
// Prior to the Durango, the VM enforces the extra data is smaller than or
58+
// equal to this size. After the Durango, the VM pre-verifies the extra
5959
// data past the dynamic fee rollup window is valid.
6060
predicateResults, err := predicate.ParseResults(predicateBytes)
6161
if err != nil {

core/predicate_check.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99

10+
"github.com/ava-labs/avalanchego/utils/set"
1011
"github.com/ava-labs/coreth/core/types"
1112
"github.com/ava-labs/coreth/params"
1213
"github.com/ava-labs/coreth/precompile/precompileconfig"
@@ -31,7 +32,7 @@ func CheckPredicates(rules params.Rules, predicateContext *precompileconfig.Pred
3132

3233
predicateResults := make(map[common.Address][]byte)
3334
// Short circuit early if there are no precompile predicates to verify
34-
if len(rules.Predicaters) == 0 {
35+
if !rules.PredicatersExist() {
3536
return predicateResults, nil
3637
}
3738

@@ -52,10 +53,15 @@ func CheckPredicates(rules params.Rules, predicateContext *precompileconfig.Pred
5253
// Since [address] is only added to [predicateArguments] when there's a valid predicate in the ruleset
5354
// there's no need to check if the predicate exists here.
5455
predicaterContract := rules.Predicaters[address]
55-
res := predicaterContract.VerifyPredicate(predicateContext, predicates)
56+
bitset := set.NewBits()
57+
for i, predicate := range predicates {
58+
if err := predicaterContract.VerifyPredicate(predicateContext, predicate); err != nil {
59+
bitset.Add(i)
60+
}
61+
}
62+
res := bitset.Bytes()
5663
log.Debug("predicate verify", "tx", tx.Hash(), "address", address, "res", res)
5764
predicateResults[address] = res
5865
}
59-
6066
return predicateResults, nil
6167
}

core/predicate_check_test.go

Lines changed: 147 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99

1010
"github.com/ava-labs/avalanchego/snow/engine/snowman/block"
11+
"github.com/ava-labs/avalanchego/utils/set"
1112
"github.com/ava-labs/coreth/core/types"
1213
"github.com/ava-labs/coreth/params"
1314
"github.com/ava-labs/coreth/precompile/precompileconfig"
@@ -31,8 +32,6 @@ func TestCheckPredicate(t *testing.T) {
3132
addr2 := common.HexToAddress("0xbb")
3233
addr3 := common.HexToAddress("0xcc")
3334
addr4 := common.HexToAddress("0xdd")
34-
predicateResultBytes1 := []byte{1, 2, 3}
35-
predicateResultBytes2 := []byte{3, 2, 1}
3635
predicateContext := &precompileconfig.PredicateContext{
3736
ProposerVMBlockCtx: &block.Context{
3837
PChainHeight: 10,
@@ -142,7 +141,7 @@ func TestCheckPredicate(t *testing.T) {
142141
predicater := precompileconfig.NewMockPredicater(gomock.NewController(t))
143142
arg := common.Hash{1}
144143
predicater.EXPECT().PredicateGas(arg[:]).Return(uint64(0), nil).Times(2)
145-
predicater.EXPECT().VerifyPredicate(gomock.Any(), [][]byte{arg[:]}).Return(predicateResultBytes1)
144+
predicater.EXPECT().VerifyPredicate(gomock.Any(), arg[:]).Return(nil)
146145
return map[common.Address]precompileconfig.Predicater{
147146
addr1: predicater,
148147
}
@@ -156,7 +155,7 @@ func TestCheckPredicate(t *testing.T) {
156155
},
157156
}),
158157
expectedRes: map[common.Address][]byte{
159-
addr1: predicateResultBytes1,
158+
addr1: {}, // valid bytes
160159
},
161160
expectedErr: nil,
162161
},
@@ -188,7 +187,7 @@ func TestCheckPredicate(t *testing.T) {
188187
predicater := precompileconfig.NewMockPredicater(gomock.NewController(t))
189188
arg := common.Hash{1}
190189
predicater.EXPECT().PredicateGas(arg[:]).Return(uint64(0), nil).Times(2)
191-
predicater.EXPECT().VerifyPredicate(gomock.Any(), [][]byte{arg[:]}).Return(predicateResultBytes1)
190+
predicater.EXPECT().VerifyPredicate(gomock.Any(), arg[:]).Return(nil)
192191
return map[common.Address]precompileconfig.Predicater{
193192
addr1: predicater,
194193
addr2: predicater,
@@ -203,7 +202,7 @@ func TestCheckPredicate(t *testing.T) {
203202
},
204203
}),
205204
expectedRes: map[common.Address][]byte{
206-
addr1: predicateResultBytes1,
205+
addr1: {}, // valid bytes
207206
},
208207
expectedErr: nil,
209208
},
@@ -215,11 +214,11 @@ func TestCheckPredicate(t *testing.T) {
215214
predicate1 := precompileconfig.NewMockPredicater(ctrl)
216215
arg1 := common.Hash{1}
217216
predicate1.EXPECT().PredicateGas(arg1[:]).Return(uint64(0), nil).Times(2)
218-
predicate1.EXPECT().VerifyPredicate(gomock.Any(), [][]byte{arg1[:]}).Return(predicateResultBytes1)
217+
predicate1.EXPECT().VerifyPredicate(gomock.Any(), arg1[:]).Return(nil)
219218
predicate2 := precompileconfig.NewMockPredicater(ctrl)
220219
arg2 := common.Hash{2}
221220
predicate2.EXPECT().PredicateGas(arg2[:]).Return(uint64(0), nil).Times(2)
222-
predicate2.EXPECT().VerifyPredicate(gomock.Any(), [][]byte{arg2[:]}).Return(predicateResultBytes2)
221+
predicate2.EXPECT().VerifyPredicate(gomock.Any(), arg2[:]).Return(testErr)
223222
return map[common.Address]precompileconfig.Predicater{
224223
addr1: predicate1,
225224
addr2: predicate2,
@@ -240,8 +239,8 @@ func TestCheckPredicate(t *testing.T) {
240239
},
241240
}),
242241
expectedRes: map[common.Address][]byte{
243-
addr1: predicateResultBytes1,
244-
addr2: predicateResultBytes2,
242+
addr1: {}, // valid bytes
243+
addr2: {1}, // invalid bytes
245244
},
246245
expectedErr: nil,
247246
},
@@ -322,3 +321,141 @@ func TestCheckPredicate(t *testing.T) {
322321
})
323322
}
324323
}
324+
325+
func TestCheckPredicatesOutput(t *testing.T) {
326+
testErr := errors.New("test error")
327+
addr1 := common.HexToAddress("0xaa")
328+
addr2 := common.HexToAddress("0xbb")
329+
validHash := common.Hash{1}
330+
invalidHash := common.Hash{2}
331+
predicateContext := &precompileconfig.PredicateContext{
332+
ProposerVMBlockCtx: &block.Context{
333+
PChainHeight: 10,
334+
},
335+
}
336+
type testTuple struct {
337+
address common.Address
338+
isValidPredicate bool
339+
}
340+
type resultTest struct {
341+
name string
342+
expectedRes map[common.Address][]byte
343+
testTuple []testTuple
344+
}
345+
tests := []resultTest{
346+
{name: "no predicates", expectedRes: map[common.Address][]byte{}},
347+
{
348+
name: "one address one predicate",
349+
testTuple: []testTuple{
350+
{address: addr1, isValidPredicate: true},
351+
},
352+
expectedRes: map[common.Address][]byte{addr1: set.NewBits().Bytes()},
353+
},
354+
{
355+
name: "one address one invalid predicate",
356+
testTuple: []testTuple{
357+
{address: addr1, isValidPredicate: false},
358+
},
359+
expectedRes: map[common.Address][]byte{addr1: set.NewBits(0).Bytes()},
360+
},
361+
{
362+
name: "one address two invalid predicates",
363+
testTuple: []testTuple{
364+
{address: addr1, isValidPredicate: false},
365+
{address: addr1, isValidPredicate: false},
366+
},
367+
expectedRes: map[common.Address][]byte{addr1: set.NewBits(0, 1).Bytes()},
368+
},
369+
{
370+
name: "one address two mixed predicates",
371+
testTuple: []testTuple{
372+
{address: addr1, isValidPredicate: true},
373+
{address: addr1, isValidPredicate: false},
374+
},
375+
expectedRes: map[common.Address][]byte{addr1: set.NewBits(1).Bytes()},
376+
},
377+
{
378+
name: "one address mixed predicates",
379+
testTuple: []testTuple{
380+
{address: addr1, isValidPredicate: true},
381+
{address: addr1, isValidPredicate: false},
382+
{address: addr1, isValidPredicate: false},
383+
{address: addr1, isValidPredicate: true},
384+
},
385+
expectedRes: map[common.Address][]byte{addr1: set.NewBits(1, 2).Bytes()},
386+
},
387+
{
388+
name: "two addresses mixed predicates",
389+
testTuple: []testTuple{
390+
{address: addr1, isValidPredicate: true},
391+
{address: addr2, isValidPredicate: false},
392+
{address: addr1, isValidPredicate: false},
393+
{address: addr1, isValidPredicate: false},
394+
{address: addr2, isValidPredicate: true},
395+
{address: addr2, isValidPredicate: true},
396+
{address: addr2, isValidPredicate: false},
397+
{address: addr2, isValidPredicate: true},
398+
},
399+
expectedRes: map[common.Address][]byte{addr1: set.NewBits(1, 2).Bytes(), addr2: set.NewBits(0, 3).Bytes()},
400+
},
401+
{
402+
name: "two addresses all valid predicates",
403+
testTuple: []testTuple{
404+
{address: addr1, isValidPredicate: true},
405+
{address: addr2, isValidPredicate: true},
406+
{address: addr1, isValidPredicate: true},
407+
{address: addr1, isValidPredicate: true},
408+
},
409+
expectedRes: map[common.Address][]byte{addr1: set.NewBits().Bytes(), addr2: set.NewBits().Bytes()},
410+
},
411+
{
412+
name: "two addresses all invalid predicates",
413+
testTuple: []testTuple{
414+
{address: addr1, isValidPredicate: false},
415+
{address: addr2, isValidPredicate: false},
416+
{address: addr1, isValidPredicate: false},
417+
{address: addr1, isValidPredicate: false},
418+
},
419+
expectedRes: map[common.Address][]byte{addr1: set.NewBits(0, 1, 2).Bytes(), addr2: set.NewBits(0).Bytes()},
420+
},
421+
}
422+
for _, test := range tests {
423+
t.Run(test.name, func(t *testing.T) {
424+
require := require.New(t)
425+
// Create the rules from TestChainConfig and update the predicates based on the test params
426+
rules := params.TestChainConfig.AvalancheRules(common.Big0, 0)
427+
predicater := precompileconfig.NewMockPredicater(gomock.NewController(t))
428+
predicater.EXPECT().PredicateGas(gomock.Any()).Return(uint64(0), nil).Times(len(test.testTuple))
429+
430+
var txAccessList types.AccessList
431+
for _, tuple := range test.testTuple {
432+
var predicateHash common.Hash
433+
if tuple.isValidPredicate {
434+
predicateHash = validHash
435+
predicater.EXPECT().VerifyPredicate(gomock.Any(), validHash[:]).Return(nil)
436+
} else {
437+
predicateHash = invalidHash
438+
predicater.EXPECT().VerifyPredicate(gomock.Any(), invalidHash[:]).Return(testErr)
439+
}
440+
txAccessList = append(txAccessList, types.AccessTuple{
441+
Address: tuple.address,
442+
StorageKeys: []common.Hash{
443+
predicateHash,
444+
},
445+
})
446+
}
447+
448+
rules.Predicaters[addr1] = predicater
449+
rules.Predicaters[addr2] = predicater
450+
451+
// Specify only the access list, since this test should not depend on any other values
452+
tx := types.NewTx(&types.DynamicFeeTx{
453+
AccessList: txAccessList,
454+
Gas: 53000,
455+
})
456+
predicateRes, err := CheckPredicates(rules, predicateContext, tx)
457+
require.NoError(err)
458+
require.Equal(test.expectedRes, predicateRes)
459+
})
460+
}
461+
}

0 commit comments

Comments
 (0)