Skip to content

Commit

Permalink
[AVAX] Merge Cortina 18 (v0.12.10-rc5)
Browse files Browse the repository at this point in the history
  • Loading branch information
knikos authored Mar 19, 2024
2 parents 165b7d6 + 1972687 commit 0e69822
Show file tree
Hide file tree
Showing 113 changed files with 3,307 additions and 1,952 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ jobs:
repository: chain4travel/caminogo
ref: ${{ github.event.inputs.caminogoBranch }}
path: caminogo
- uses: actions/setup-go@v2
- uses: actions/setup-go@v3
with:
go-version: '~1.20.10'
go-version: '~1.20.12'
check-latest: true
- name: change caminogo dep
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.caminogoBranch != '' }}
run: |
Expand Down Expand Up @@ -77,7 +78,7 @@ jobs:
path: caminogo
- uses: actions/setup-go@v2
with:
go-version: '~1.20.10'
go-version: '~1.20.12'
check-latest: true
- name: change caminogo dep
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.caminogoBranch != '' }}
Expand Down Expand Up @@ -117,7 +118,7 @@ jobs:
path: caminogo
- uses: actions/setup-go@v2
with:
go-version: '~1.20.10'
go-version: '~1.20.12'
check-latest: true
- name: change caminogo dep
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.caminogoBranch != '' }}
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# ============= Compilation Stage ================
FROM golang:1.20.10-bullseye AS builder
FROM golang:1.20.12-bullseye AS builder

ARG CAMINO_VERSION

Expand Down
12 changes: 6 additions & 6 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,12 @@ func (abi ABI) PackOutput(name string, args ...interface{}) ([]byte, error) {
}

// getInputs gets input arguments of the given [name] method.
func (abi ABI) getInputs(name string, data []byte) (Arguments, error) {
func (abi ABI) getInputs(name string, data []byte, useStrictMode bool) (Arguments, error) {
// since there can't be naming collisions with contracts and events,
// we need to decide whether we're calling a method or an event
var args Arguments
if method, ok := abi.Methods[name]; ok {
if len(data)%32 != 0 {
if useStrictMode && len(data)%32 != 0 {
return nil, fmt.Errorf("abi: improperly formatted input: %s - Bytes: [%+v]", string(data), data)
}
args = method.Inputs
Expand Down Expand Up @@ -196,8 +196,8 @@ func (abi ABI) getArguments(name string, data []byte) (Arguments, error) {
}

// UnpackInput unpacks the input according to the ABI specification.
func (abi ABI) UnpackInput(name string, data []byte) ([]interface{}, error) {
args, err := abi.getInputs(name, data)
func (abi ABI) UnpackInput(name string, data []byte, useStrictMode bool) ([]interface{}, error) {
args, err := abi.getInputs(name, data, useStrictMode)
if err != nil {
return nil, err
}
Expand All @@ -216,8 +216,8 @@ func (abi ABI) Unpack(name string, data []byte) ([]interface{}, error) {
// UnpackInputIntoInterface unpacks the input in v according to the ABI specification.
// It performs an additional copy. Please only use, if you want to unpack into a
// structure that does not strictly conform to the ABI structure (e.g. has additional arguments)
func (abi ABI) UnpackInputIntoInterface(v interface{}, name string, data []byte) error {
args, err := abi.getInputs(name, data)
func (abi ABI) UnpackInputIntoInterface(v interface{}, name string, data []byte, useStrictMode bool) error {
args, err := abi.getInputs(name, data, useStrictMode)
if err != nil {
return err
}
Expand Down
111 changes: 111 additions & 0 deletions accounts/abi/abi_extra_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// (c) 2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.

package abi

import (
"bytes"
"math/big"
"strings"
"testing"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
)

// Note: This file contains tests in addition to those found in go-ethereum.

const TEST_ABI = `[{"type":"function","name":"receive","inputs":[{"name":"sender","type":"address"},{"name":"amount","type":"uint256"},{"name":"memo","type":"bytes"}],"outputs":[{"internalType":"bool","name":"isAllowed","type":"bool"}]}]`

func TestUnpackInputIntoInterface(t *testing.T) {
abi, err := JSON(strings.NewReader(TEST_ABI))
require.NoError(t, err)

type inputType struct {
Sender common.Address
Amount *big.Int
Memo []byte
}
input := inputType{
Sender: common.HexToAddress("0x02"),
Amount: big.NewInt(100),
Memo: []byte("hello"),
}

rawData, err := abi.Pack("receive", input.Sender, input.Amount, input.Memo)
require.NoError(t, err)

abi, err = JSON(strings.NewReader(TEST_ABI))
require.NoError(t, err)

for _, test := range []struct {
name string
extraPaddingBytes int
strictMode bool
expectedErrorSubstring string
}{
{
name: "No extra padding to input data",
strictMode: true,
},
{
name: "Valid input data with 32 extra padding(%32) ",
extraPaddingBytes: 32,
strictMode: true,
},
{
name: "Valid input data with 64 extra padding(%32)",
extraPaddingBytes: 64,
strictMode: true,
},
{
name: "Valid input data with extra padding indivisible by 32",
extraPaddingBytes: 33,
strictMode: true,
expectedErrorSubstring: "abi: improperly formatted input:",
},
{
name: "Valid input data with extra padding indivisible by 32, no strict mode",
extraPaddingBytes: 33,
strictMode: false,
},
} {
{
t.Run(test.name, func(t *testing.T) {
// skip 4 byte selector
data := rawData[4:]
// Add extra padding to data
data = append(data, make([]byte, test.extraPaddingBytes)...)

// Unpack into interface
var v inputType
err = abi.UnpackInputIntoInterface(&v, "receive", data, test.strictMode) // skips 4 byte selector

if test.expectedErrorSubstring != "" {
require.Error(t, err)
require.ErrorContains(t, err, test.expectedErrorSubstring)
} else {
require.NoError(t, err)
// Verify unpacked values match input
require.Equal(t, v.Amount, input.Amount)
require.EqualValues(t, v.Amount, input.Amount)
require.True(t, bytes.Equal(v.Memo, input.Memo))
}
})
}
}
}

func TestPackOutput(t *testing.T) {
abi, err := JSON(strings.NewReader(TEST_ABI))
require.NoError(t, err)

bytes, err := abi.PackOutput("receive", true)
require.NoError(t, err)

vals, err := abi.Methods["receive"].Outputs.Unpack(bytes)
require.NoError(t, err)

require.Len(t, vals, 1)
require.True(t, vals[0].(bool))
}
4 changes: 2 additions & 2 deletions accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -954,8 +954,8 @@ func (fb *filterBackend) SubscribeAcceptedTransactionEvent(ch chan<- core.NewTxs
return fb.bc.SubscribeAcceptedTransactionEvent(ch)
}

func (fb *filterBackend) GetVMConfig() *vm.Config {
return fb.bc.GetVMConfig()
func (fb *filterBackend) IsAllowUnfinalizedQueries() bool {
return false
}

func (fb *filterBackend) LastAcceptedBlock() *types.Block {
Expand Down
2 changes: 1 addition & 1 deletion accounts/abi/bind/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2184,7 +2184,7 @@ func golangBindings(t *testing.T, overload bool) {
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
}
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/avalanchego@v0.0.0", "-replace", "github.com/ava-labs/avalanchego=github.com/chain4travel/caminogo@v1.0.0-rc1") // Repo root
replacer = exec.Command(gocmd, "mod", "edit", "-x", "-require", "github.com/ava-labs/avalanchego@v0.0.0", "-replace", "github.com/ava-labs/avalanchego=github.com/chain4travel/caminogo@v1.1.18-rc0") // Repo root
replacer.Dir = pkg
if out, err := replacer.CombinedOutput(); err != nil {
t.Fatalf("failed to replace binding test dependency to current source tree: %v\n%s", err, out)
Expand Down
4 changes: 1 addition & 3 deletions accounts/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
return Type{}, errors.New("abi: purely anonymous or underscored field is not supported")
}
fieldName := ResolveNameConflict(name, func(s string) bool { return used[s] })
if err != nil {
return Type{}, err
}

used[fieldName] = true
if !isValidFieldName(fieldName) {
return Type{}, fmt.Errorf("field %d has invalid name", idx)
Expand Down
11 changes: 5 additions & 6 deletions consensus/dummy/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,13 @@ func (self *DummyEngine) verifyHeaderGasFields(config *params.ChainConfig, ctrl

// modified from consensus.go
func (self *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header *types.Header, parent *types.Header, uncle bool) error {
var (
config = chain.Config()
)
config := chain.Config()
// Ensure that we do not verify an uncle
if uncle {
return errUnclesUnsupported
}
switch {
case config.IsDUpgrade(header.Time):
case config.IsDurango(header.Time):
if len(header.Extra) < params.DynamicFeeExtraDataSize {
return fmt.Errorf("expected extra-data field length >= %d, found %d", params.DynamicFeeExtraDataSize, len(header.Extra))
}
Expand All @@ -235,7 +233,7 @@ func (self *DummyEngine) verifyHeader(chain consensus.ChainHeaderReader, header
if header.Time > uint64(time.Now().Add(allowedFutureBlockTime).Unix()) {
return consensus.ErrFutureBlock
}
//if header.Time <= parent.Time {
// if header.Time <= parent.Time {
if header.Time < parent.Time {
return errInvalidBlockTime
}
Expand Down Expand Up @@ -416,7 +414,8 @@ func (self *DummyEngine) Finalize(chain consensus.ChainHeaderReader, block *type
}

func (self *DummyEngine) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, parent *types.Header, state *state.StateDB, txs []*types.Transaction,
uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
uncles []*types.Header, receipts []*types.Receipt,
) (*types.Block, error) {
var (
contribution, extDataGasUsed *big.Int
extraData []byte
Expand Down
12 changes: 4 additions & 8 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,10 @@ type BlockChain struct {

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

engine consensus.Engine
validator Validator // Block and state validator interface
prefetcher Prefetcher // Block state prefetcher interface
processor Processor // Block transaction processor interface
vmConfig vm.Config
engine consensus.Engine
validator Validator // Block and state validator interface
processor Processor // Block transaction processor interface
vmConfig vm.Config

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

Expand Down Expand Up @@ -346,7 +345,6 @@ func NewBlockChain(
}
bc.stateCache = state.NewDatabaseWithNodeDB(bc.db, bc.triedb)
bc.validator = NewBlockValidator(chainConfig, bc, engine)
bc.prefetcher = newStatePrefetcher(chainConfig, bc, engine)
bc.processor = NewStateProcessor(chainConfig, bc, engine)

bc.hc, err = NewHeaderChain(db, chainConfig, cacheConfig, engine)
Expand Down Expand Up @@ -1332,8 +1330,6 @@ func (bc *BlockChain) insertBlock(block *types.Block, writes bool) error {
statedb.StartPrefetcher("chain", bc.cacheConfig.TriePrefetcherParallelism)
activeState = statedb

// If we have a followup block, run that against the current state to pre-cache
// transactions and probabilistically some of the account/storage trie nodes.
// Process block using the parent state as reference point
pstart := time.Now()
receipts, logs, usedGas, err := bc.processor.Process(block, parent, statedb, bc.vmConfig)
Expand Down
4 changes: 2 additions & 2 deletions core/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
if !ok {
return newEVMBlockContext(header, chain, author, nil)
}
// Prior to the DUpgrade, the VM enforces the extra data is smaller than or
// equal to this size. After the DUpgrade, the VM pre-verifies the extra
// Prior to the Durango, the VM enforces the extra data is smaller than or
// equal to this size. After the Durango, the VM pre-verifies the extra
// data past the dynamic fee rollup window is valid.
predicateResults, err := predicate.ParseResults(predicateBytes)
if err != nil {
Expand Down
12 changes: 9 additions & 3 deletions core/predicate_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"

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

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

Expand All @@ -52,10 +53,15 @@ func CheckPredicates(rules params.Rules, predicateContext *precompileconfig.Pred
// Since [address] is only added to [predicateArguments] when there's a valid predicate in the ruleset
// there's no need to check if the predicate exists here.
predicaterContract := rules.Predicaters[address]
res := predicaterContract.VerifyPredicate(predicateContext, predicates)
bitset := set.NewBits()
for i, predicate := range predicates {
if err := predicaterContract.VerifyPredicate(predicateContext, predicate); err != nil {
bitset.Add(i)
}
}
res := bitset.Bytes()
log.Debug("predicate verify", "tx", tx.Hash(), "address", address, "res", res)
predicateResults[address] = res
}

return predicateResults, nil
}
Loading

0 comments on commit 0e69822

Please sign in to comment.