Commit 1fff77e7 authored by luxq's avatar luxq

update code

parent 323d4af7
# ethtracer
# todo: modify types/transaction types/receipt types/block types/header to evm/evmtypes.
\ No newline at end of file
......@@ -17,10 +17,9 @@
package vm
import (
"code.wuban.net.cn/cmpchain/ethcrypto/crypto"
"math/bits"
"testing"
"github.com/ethereum/go-ethereum/crypto"
)
func TestJumpDestAnalysis(t *testing.T) {
......
......@@ -17,14 +17,13 @@
package vm
import (
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"testing"
"github.com/ethereum/go-ethereum/common"
)
func FuzzPrecompiledContracts(f *testing.F) {
// Create list of addresses
var addrs []common.Address
var addrs []metatypes.Address
for k := range allPrecompiles {
addrs = append(addrs, k)
}
......
......@@ -20,11 +20,10 @@ import (
"bytes"
"encoding/json"
"fmt"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"os"
"testing"
"time"
"github.com/ethereum/go-ethereum/common"
)
// precompiledTest defines the input/output pairs for precompiled contract tests.
......@@ -45,26 +44,26 @@ type precompiledFailureTest struct {
// allPrecompiles does not map to the actual set of precompiles, as it also contains
// repriced versions of precompiles at certain slots
var allPrecompiles = map[common.Address]PrecompiledContract{
common.BytesToAddress([]byte{1}): &ecrecover{},
common.BytesToAddress([]byte{2}): &sha256hash{},
common.BytesToAddress([]byte{3}): &ripemd160hash{},
common.BytesToAddress([]byte{4}): &dataCopy{},
common.BytesToAddress([]byte{5}): &bigModExp{eip2565: false},
common.BytesToAddress([]byte{0xf5}): &bigModExp{eip2565: true},
common.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
common.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
common.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
common.BytesToAddress([]byte{9}): &blake2F{},
common.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
common.BytesToAddress([]byte{0x0f, 0x0a}): &bls12381G1Add{},
common.BytesToAddress([]byte{0x0f, 0x0b}): &bls12381G1MultiExp{},
common.BytesToAddress([]byte{0x0f, 0x0c}): &bls12381G2Add{},
common.BytesToAddress([]byte{0x0f, 0x0d}): &bls12381G2MultiExp{},
common.BytesToAddress([]byte{0x0f, 0x0e}): &bls12381Pairing{},
common.BytesToAddress([]byte{0x0f, 0x0f}): &bls12381MapG1{},
common.BytesToAddress([]byte{0x0f, 0x10}): &bls12381MapG2{},
var allPrecompiles = map[metatypes.Address]PrecompiledContract{
metatypes.BytesToAddress([]byte{1}): &ecrecover{},
metatypes.BytesToAddress([]byte{2}): &sha256hash{},
metatypes.BytesToAddress([]byte{3}): &ripemd160hash{},
metatypes.BytesToAddress([]byte{4}): &dataCopy{},
metatypes.BytesToAddress([]byte{5}): &bigModExp{eip2565: false},
metatypes.BytesToAddress([]byte{0xf5}): &bigModExp{eip2565: true},
metatypes.BytesToAddress([]byte{6}): &bn256AddIstanbul{},
metatypes.BytesToAddress([]byte{7}): &bn256ScalarMulIstanbul{},
metatypes.BytesToAddress([]byte{8}): &bn256PairingIstanbul{},
metatypes.BytesToAddress([]byte{9}): &blake2F{},
metatypes.BytesToAddress([]byte{0x0a}): &kzgPointEvaluation{},
metatypes.BytesToAddress([]byte{0x0f, 0x0a}): &bls12381G1Add{},
metatypes.BytesToAddress([]byte{0x0f, 0x0b}): &bls12381G1MultiExp{},
metatypes.BytesToAddress([]byte{0x0f, 0x0c}): &bls12381G2Add{},
metatypes.BytesToAddress([]byte{0x0f, 0x0d}): &bls12381G2MultiExp{},
metatypes.BytesToAddress([]byte{0x0f, 0x0e}): &bls12381Pairing{},
metatypes.BytesToAddress([]byte{0x0f, 0x0f}): &bls12381MapG1{},
metatypes.BytesToAddress([]byte{0x0f, 0x10}): &bls12381MapG2{},
}
// EIP-152 test vectors
......@@ -92,20 +91,20 @@ var blake2FMalformedInputTests = []precompiledFailureTest{
}
func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
p := allPrecompiles[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.Input)
p := allPrecompiles[metatypes.HexToAddress(addr)]
in := metatypes.Hex2Bytes(test.Input)
gas := p.RequiredGas(in)
t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) {
if res, _, err := RunPrecompiledContract(p, in, gas, nil); err != nil {
t.Error(err)
} else if common.Bytes2Hex(res) != test.Expected {
t.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res))
} else if metatypes.Bytes2Hex(res) != test.Expected {
t.Errorf("Expected %v, got %v", test.Expected, metatypes.Bytes2Hex(res))
}
if expGas := test.Gas; expGas != gas {
t.Errorf("%v: gas wrong, expected %d, got %d", test.Name, expGas, gas)
}
// Verify that the precompile did not touch the input buffer
exp := common.Hex2Bytes(test.Input)
exp := metatypes.Hex2Bytes(test.Input)
if !bytes.Equal(in, exp) {
t.Errorf("Precompiled %v modified input data", addr)
}
......@@ -113,8 +112,8 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
}
func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
p := allPrecompiles[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.Input)
p := allPrecompiles[metatypes.HexToAddress(addr)]
in := metatypes.Hex2Bytes(test.Input)
gas := p.RequiredGas(in) - 1
t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) {
......@@ -123,7 +122,7 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
t.Errorf("Expected error [out of gas], got [%v]", err)
}
// Verify that the precompile did not touch the input buffer
exp := common.Hex2Bytes(test.Input)
exp := metatypes.Hex2Bytes(test.Input)
if !bytes.Equal(in, exp) {
t.Errorf("Precompiled %v modified input data", addr)
}
......@@ -131,8 +130,8 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
}
func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing.T) {
p := allPrecompiles[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.Input)
p := allPrecompiles[metatypes.HexToAddress(addr)]
in := metatypes.Hex2Bytes(test.Input)
gas := p.RequiredGas(in)
t.Run(test.Name, func(t *testing.T) {
_, _, err := RunPrecompiledContract(p, in, gas, nil)
......@@ -140,7 +139,7 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing
t.Errorf("Expected error [%v], got [%v]", test.ExpectedError, err)
}
// Verify that the precompile did not touch the input buffer
exp := common.Hex2Bytes(test.Input)
exp := metatypes.Hex2Bytes(test.Input)
if !bytes.Equal(in, exp) {
t.Errorf("Precompiled %v modified input data", addr)
}
......@@ -151,8 +150,8 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
if test.NoBenchmark {
return
}
p := allPrecompiles[common.HexToAddress(addr)]
in := common.Hex2Bytes(test.Input)
p := allPrecompiles[metatypes.HexToAddress(addr)]
in := metatypes.Hex2Bytes(test.Input)
reqGas := p.RequiredGas(in)
var (
......@@ -184,8 +183,8 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
bench.Error(err)
return
}
if common.Bytes2Hex(res) != test.Expected {
bench.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res))
if metatypes.Bytes2Hex(res) != test.Expected {
bench.Errorf("Expected %v, got %v", test.Expected, metatypes.Bytes2Hex(res))
return
}
})
......
......@@ -18,10 +18,9 @@ package vm
import (
"encoding/hex"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"reflect"
"testing"
"github.com/ethereum/go-ethereum/common"
)
func TestEOFMarshaling(t *testing.T) {
......@@ -32,7 +31,7 @@ func TestEOFMarshaling(t *testing.T) {
{
want: Container{
types: []*functionMetadata{{inputs: 0, outputs: 0x80, maxStackHeight: 1}},
codeSections: [][]byte{common.Hex2Bytes("604200")},
codeSections: [][]byte{metatypes.Hex2Bytes("604200")},
data: []byte{0x01, 0x02, 0x03},
dataSize: 3,
},
......@@ -40,7 +39,7 @@ func TestEOFMarshaling(t *testing.T) {
{
want: Container{
types: []*functionMetadata{{inputs: 0, outputs: 0x80, maxStackHeight: 1}},
codeSections: [][]byte{common.Hex2Bytes("604200")},
codeSections: [][]byte{metatypes.Hex2Bytes("604200")},
data: []byte{0x01, 0x02, 0x03},
dataSize: 3,
},
......@@ -53,9 +52,9 @@ func TestEOFMarshaling(t *testing.T) {
{inputs: 1, outputs: 1, maxStackHeight: 1},
},
codeSections: [][]byte{
common.Hex2Bytes("604200"),
common.Hex2Bytes("6042604200"),
common.Hex2Bytes("00"),
metatypes.Hex2Bytes("604200"),
metatypes.Hex2Bytes("6042604200"),
metatypes.Hex2Bytes("00"),
},
data: []byte{},
},
......@@ -77,12 +76,12 @@ func TestEOFMarshaling(t *testing.T) {
func TestEOFSubcontainer(t *testing.T) {
var subcontainer = new(Container)
if err := subcontainer.UnmarshalBinary(common.Hex2Bytes("ef000101000402000100010400000000800000fe"), true); err != nil {
if err := subcontainer.UnmarshalBinary(metatypes.Hex2Bytes("ef000101000402000100010400000000800000fe"), true); err != nil {
t.Fatal(err)
}
container := Container{
types: []*functionMetadata{{inputs: 0, outputs: 0x80, maxStackHeight: 1}},
codeSections: [][]byte{common.Hex2Bytes("604200")},
codeSections: [][]byte{metatypes.Hex2Bytes("604200")},
subContainers: []*Container{subcontainer},
data: []byte{0x01, 0x02, 0x03},
dataSize: 3,
......
......@@ -17,12 +17,11 @@
package vm
import (
"code.wuban.net.cn/cmpchain/ethtracer/params"
"encoding/binary"
"errors"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/params"
)
func TestValidateCode(t *testing.T) {
......@@ -253,7 +252,7 @@ func TestValidateCode(t *testing.T) {
}
_, err := validateCode(test.code, test.section, container, &eofInstructionSet, false)
if !errors.Is(err, test.err) {
t.Errorf("test %d (%s): unexpected error (want: %v, got: %v)", i, common.Bytes2Hex(test.code), test.err, err)
t.Errorf("test %d (%s): unexpected error (want: %v, got: %v)", i, metatypes.Bytes2Hex(test.code), test.err, err)
}
}
}
......
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package vm
import (
"bytes"
"errors"
"math"
"math/big"
"sort"
"testing"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
)
func TestMemoryGasCost(t *testing.T) {
tests := []struct {
size uint64
cost uint64
overflow bool
}{
{0x1fffffffe0, 36028809887088637, false},
{0x1fffffffe1, 0, true},
}
for i, tt := range tests {
v, err := memoryGasCost(&Memory{}, tt.size)
if (err == ErrGasUintOverflow) != tt.overflow {
t.Errorf("test %d: overflow mismatch: have %v, want %v", i, err == ErrGasUintOverflow, tt.overflow)
}
if v != tt.cost {
t.Errorf("test %d: gas cost mismatch: have %v, want %v", i, v, tt.cost)
}
}
}
var eip2200Tests = []struct {
original byte
gaspool uint64
input string
used uint64
refund uint64
failure error
}{
{0, math.MaxUint64, "0x60006000556000600055", 1612, 0, nil}, // 0 -> 0 -> 0
{0, math.MaxUint64, "0x60006000556001600055", 20812, 0, nil}, // 0 -> 0 -> 1
{0, math.MaxUint64, "0x60016000556000600055", 20812, 19200, nil}, // 0 -> 1 -> 0
{0, math.MaxUint64, "0x60016000556002600055", 20812, 0, nil}, // 0 -> 1 -> 2
{0, math.MaxUint64, "0x60016000556001600055", 20812, 0, nil}, // 0 -> 1 -> 1
{1, math.MaxUint64, "0x60006000556000600055", 5812, 15000, nil}, // 1 -> 0 -> 0
{1, math.MaxUint64, "0x60006000556001600055", 5812, 4200, nil}, // 1 -> 0 -> 1
{1, math.MaxUint64, "0x60006000556002600055", 5812, 0, nil}, // 1 -> 0 -> 2
{1, math.MaxUint64, "0x60026000556000600055", 5812, 15000, nil}, // 1 -> 2 -> 0
{1, math.MaxUint64, "0x60026000556003600055", 5812, 0, nil}, // 1 -> 2 -> 3
{1, math.MaxUint64, "0x60026000556001600055", 5812, 4200, nil}, // 1 -> 2 -> 1
{1, math.MaxUint64, "0x60026000556002600055", 5812, 0, nil}, // 1 -> 2 -> 2
{1, math.MaxUint64, "0x60016000556000600055", 5812, 15000, nil}, // 1 -> 1 -> 0
{1, math.MaxUint64, "0x60016000556002600055", 5812, 0, nil}, // 1 -> 1 -> 2
{1, math.MaxUint64, "0x60016000556001600055", 1612, 0, nil}, // 1 -> 1 -> 1
{0, math.MaxUint64, "0x600160005560006000556001600055", 40818, 19200, nil}, // 0 -> 1 -> 0 -> 1
{1, math.MaxUint64, "0x600060005560016000556000600055", 10818, 19200, nil}, // 1 -> 0 -> 1 -> 0
{1, 2306, "0x6001600055", 2306, 0, ErrOutOfGas}, // 1 -> 1 (2300 sentry + 2xPUSH)
{1, 2307, "0x6001600055", 806, 0, nil}, // 1 -> 1 (2301 sentry + 2xPUSH)
}
func TestEIP2200(t *testing.T) {
for i, tt := range eip2200Tests {
address := common.BytesToAddress([]byte("contract"))
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
statedb.CreateAccount(address)
statedb.SetCode(address, hexutil.MustDecode(tt.input))
statedb.SetState(address, common.Hash{}, common.BytesToHash([]byte{tt.original}))
statedb.Finalise(true) // Push the state into the "original" slot
vmctx := BlockContext{
CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true },
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int) {},
}
evm := NewEVM(vmctx, statedb, params.AllEthashProtocolChanges, Config{ExtraEips: []int{2200}})
_, gas, err := evm.Call(common.Address{}, address, nil, tt.gaspool, new(uint256.Int))
if !errors.Is(err, tt.failure) {
t.Errorf("test %d: failure mismatch: have %v, want %v", i, err, tt.failure)
}
if used := tt.gaspool - gas; used != tt.used {
t.Errorf("test %d: gas used mismatch: have %v, want %v", i, used, tt.used)
}
if refund := evm.StateDB.GetRefund(); refund != tt.refund {
t.Errorf("test %d: gas refund mismatch: have %v, want %v", i, refund, tt.refund)
}
}
}
var createGasTests = []struct {
code string
eip3860 bool
gasUsed uint64
minimumGas uint64
}{
// legacy create(0, 0, 0xc000) without 3860 used
{"0x61C00060006000f0" + "600052" + "60206000F3", false, 41237, 41237},
// legacy create(0, 0, 0xc000) _with_ 3860
{"0x61C00060006000f0" + "600052" + "60206000F3", true, 44309, 44309},
// create2(0, 0, 0xc001, 0) without 3860
{"0x600061C00160006000f5" + "600052" + "60206000F3", false, 50471, 50471},
// create2(0, 0, 0xc001, 0) (too large), with 3860
{"0x600061C00160006000f5" + "600052" + "60206000F3", true, 32012, 100_000},
// create2(0, 0, 0xc000, 0)
// This case is trying to deploy code at (within) the limit
{"0x600061C00060006000f5" + "600052" + "60206000F3", true, 53528, 53528},
// create2(0, 0, 0xc001, 0)
// This case is trying to deploy code exceeding the limit
{"0x600061C00160006000f5" + "600052" + "60206000F3", true, 32024, 100000},
}
func TestCreateGas(t *testing.T) {
for i, tt := range createGasTests {
var gasUsed = uint64(0)
doCheck := func(testGas int) bool {
address := common.BytesToAddress([]byte("contract"))
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
statedb.CreateAccount(address)
statedb.SetCode(address, hexutil.MustDecode(tt.code))
statedb.Finalise(true)
vmctx := BlockContext{
CanTransfer: func(StateDB, common.Address, *uint256.Int) bool { return true },
Transfer: func(StateDB, common.Address, common.Address, *uint256.Int) {},
BlockNumber: big.NewInt(0),
}
config := Config{}
if tt.eip3860 {
config.ExtraEips = []int{3860}
}
evm := NewEVM(vmctx, statedb, params.AllEthashProtocolChanges, config)
var startGas = uint64(testGas)
ret, gas, err := evm.Call(common.Address{}, address, nil, startGas, new(uint256.Int))
if err != nil {
return false
}
gasUsed = startGas - gas
if len(ret) != 32 {
t.Fatalf("test %d: expected 32 bytes returned, have %d", i, len(ret))
}
if bytes.Equal(ret, make([]byte, 32)) {
// Failure
return false
}
return true
}
minGas := sort.Search(100_000, doCheck)
if uint64(minGas) != tt.minimumGas {
t.Fatalf("test %d: min gas error, want %d, have %d", i, tt.minimumGas, minGas)
}
// If the deployment succeeded, we also check the gas used
if minGas < 100_000 {
if gasUsed != tt.gasUsed {
t.Errorf("test %d: gas used mismatch: have %v, want %v", i, gasUsed, tt.gasUsed)
}
}
}
}
......@@ -18,9 +18,9 @@ package vm
import (
"code.wuban.net.cn/cmpchain/ethcrypto/crypto"
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
"code.wuban.net.cn/cmpchain/ethtracer/params"
"code.wuban.net.cn/cmpchain/ethtracer/tracing"
"code.wuban.net.cn/cmpchain/ethtracer/types"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"math"
......@@ -943,7 +943,12 @@ func makeLog(size int) executionFunc {
}
d := scope.Memory.GetCopy(mStart.Uint64(), mSize.Uint64())
interpreter.evm.StateDB.AddLog(types.NewLog(scope.Contract.Address(), topics, d, interpreter.evm.Context.BlockNumber.Uint64()))
interpreter.evm.StateDB.AddLog(&evmtypes.Log{
Address: scope.Contract.Address(),
Topics: topics,
Data: d,
BlockNumber: interpreter.evm.Context.BlockNumber.Uint64(),
})
return nil, nil
}
......
This diff is collapsed.
......@@ -22,7 +22,6 @@ import (
"code.wuban.net.cn/cmpchain/ethtracer/state"
"code.wuban.net.cn/cmpchain/ethtracer/stateless"
"code.wuban.net.cn/cmpchain/ethtracer/tracing"
"code.wuban.net.cn/cmpchain/ethtracer/types"
"code.wuban.net.cn/cmpchain/ethtracer/utils"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
......@@ -96,9 +95,9 @@ type StateDB interface {
RevertToSnapshot(int)
Snapshot() int
AddLog(*types.Log)
AddLog(*evmtypes.Log)
AddPreimage(metatypes.Hash, []byte)
Witness() *stateless.Witness
AccessEvents() *state.AccessEvents
......
// Copyright 2021 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package vm
import (
"code.wuban.net.cn/cmpchain/ethtracer/params"
"code.wuban.net.cn/cmpchain/ethtracer/types"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/ethereum/go-ethereum/core/state"
"math"
"testing"
"time"
"github.com/holiman/uint256"
)
var loopInterruptTests = []string{
// infinite loop using JUMP: push(2) jumpdest dup1 jump
"60025b8056",
// infinite loop using JUMPI: push(1) push(4) jumpdest dup2 dup2 jumpi
"600160045b818157",
}
func TestLoopInterrupt(t *testing.T) {
address := metatypes.BytesToAddress([]byte("contract"))
vmctx := BlockContext{
Transfer: func(StateDB, metatypes.Address, metatypes.Address, *uint256.Int) {},
}
for i, tt := range loopInterruptTests {
statedb, _ := state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
statedb.CreateAccount(address)
statedb.SetCode(address, metatypes.Hex2Bytes(tt))
statedb.Finalise(true)
evm := NewEVM(vmctx, statedb, params.AllEthashProtocolChanges, Config{})
errChannel := make(chan error)
timeout := make(chan bool)
go func(evm *EVM) {
_, _, err := evm.Call(metatypes.Address{}, address, nil, math.MaxUint64, new(uint256.Int))
errChannel <- err
}(evm)
go func() {
<-time.After(time.Second)
timeout <- true
}()
evm.Cancel()
select {
case <-timeout:
t.Errorf("test %d timed out", i)
case err := <-errChannel:
if err != nil {
t.Errorf("test %d failure: %v", i, err)
}
}
}
}
......@@ -18,10 +18,9 @@ package vm
import (
"bytes"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"strings"
"testing"
"github.com/ethereum/go-ethereum/common"
)
func TestMemoryCopy(t *testing.T) {
......@@ -71,13 +70,13 @@ func TestMemoryCopy(t *testing.T) {
} {
m := NewMemory()
// Clean spaces
data := common.FromHex(strings.ReplaceAll(tc.pre, " ", ""))
data := metatypes.FromHex(strings.ReplaceAll(tc.pre, " ", ""))
// Set pre
m.Resize(uint64(len(data)))
m.Set(0, uint64(len(data)), data)
// Do the copy
m.Copy(tc.dst, tc.src, tc.len)
want := common.FromHex(strings.ReplaceAll(tc.want, " ", ""))
want := metatypes.FromHex(strings.ReplaceAll(tc.want, " ", ""))
if have := m.store; !bytes.Equal(want, have) {
t.Errorf("case %d: want: %#x\nhave: %#x\n", i, want, have)
}
......
......@@ -21,11 +21,8 @@ import (
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
"code.wuban.net.cn/cmpchain/ethtracer/evm/vm"
"code.wuban.net.cn/cmpchain/ethtracer/params"
"code.wuban.net.cn/cmpchain/ethtracer/types"
"errors"
basetype "github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/base/v1"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/ethereum/go-ethereum/core/state"
"math"
"math/big"
......@@ -153,7 +150,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, vm.StateDB, error) {
uint256.MustFromBig(cfg.Value),
)
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil {
cfg.EVMConfig.Tracer.OnTxEnd(&types.Receipt{GasUsed: cfg.GasLimit - leftOverGas}, err)
cfg.EVMConfig.Tracer.OnTxEnd(&evmtypes.Receipt{GasUsed: cfg.GasLimit - leftOverGas}, err)
}
return ret, cfg.State, err
}
......@@ -166,14 +163,15 @@ func Create(input []byte, cfg *Config) ([]byte, metatypes.Address, uint64, error
setDefaults(cfg)
if cfg.State == nil {
cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
return nil, metatypes.Address{}, 0, errors.New("state must be set in config for Create")
//cfg.State, _ = state.New(types.EmptyRootHash, state.NewDatabaseForTesting())
}
var (
vmenv = NewEnv(cfg)
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Random != nil, vmenv.Context.Time)
)
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxStart != nil {
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), evmtypes.NewTx(&evmtypes.LegacyTx{Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
}
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
......@@ -187,10 +185,8 @@ func Create(input []byte, cfg *Config) ([]byte, metatypes.Address, uint64, error
uint256.MustFromBig(cfg.Value),
)
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil {
cfg.EVMConfig.Tracer.OnTxEnd(&types.Receipt{
MetaReceipt: &basetype.MetaReceipt{
GasUsed: cfg.GasLimit - leftOverGas,
},
cfg.EVMConfig.Tracer.OnTxEnd(&evmtypes.Receipt{
GasUsed: cfg.GasLimit - leftOverGas,
}, err)
}
return code, address, leftOverGas, err
......@@ -210,7 +206,7 @@ func Call(address metatypes.Address, input []byte, cfg *Config) ([]byte, uint64,
rules = cfg.ChainConfig.Rules(vmenv.Context.BlockNumber, vmenv.Context.Random != nil, vmenv.Context.Time)
)
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxStart != nil {
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), types.NewTx(&types.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
cfg.EVMConfig.Tracer.OnTxStart(vmenv.GetVMContext(), evmtypes.NewTx(&evmtypes.LegacyTx{To: &address, Data: input, Value: cfg.Value, Gas: cfg.GasLimit}), cfg.Origin)
}
// Execute the preparatory steps for state transition which includes:
// - prepare accessList(post-berlin)
......@@ -226,11 +222,14 @@ func Call(address metatypes.Address, input []byte, cfg *Config) ([]byte, uint64,
uint256.MustFromBig(cfg.Value),
)
if cfg.EVMConfig.Tracer != nil && cfg.EVMConfig.Tracer.OnTxEnd != nil {
cfg.EVMConfig.Tracer.OnTxEnd(&types.Receipt{
MetaReceipt: &basetype.MetaReceipt{
GasUsed: cfg.GasLimit - leftOverGas,
},
cfg.EVMConfig.Tracer.OnTxEnd(&evmtypes.Receipt{
GasUsed: cfg.GasLimit - leftOverGas,
}, err)
//cfg.EVMConfig.Tracer.OnTxEnd(&types.Receipt{
// MetaReceipt: &basetype.MetaReceipt{
// GasUsed: cfg.GasLimit - leftOverGas,
// },
//}, err)
}
return ret, leftOverGas, err
}
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package runtime_test
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm/runtime"
)
func ExampleExecute() {
ret, _, err := runtime.Execute(common.Hex2Bytes("6060604052600a8060106000396000f360606040526008565b00"), nil, nil)
if err != nil {
fmt.Println(err)
}
fmt.Println(ret)
// Output:
// [96 96 96 64 82 96 8 86 91 0]
}
// Copyright 2023 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package runtime
import (
"testing"
)
func FuzzVmRuntime(f *testing.F) {
f.Fuzz(func(t *testing.T, code, input []byte) {
Execute(code, input, &Config{
GasLimit: 12000000,
})
})
}
This diff is collapsed.
......@@ -3,33 +3,27 @@ module code.wuban.net.cn/cmpchain/ethtracer
go 1.24.0
require (
github.com/CaduceusMetaverseProtocol/MetaProtocol v0.0.0-00010101000000-000000000000
code.wuban.net.cn/cmpchain/ethcrypto v0.0.0-20250707071006-5c3f8f42b6ad
github.com/CaduceusMetaverseProtocol/MetaTypes v1.0.0
github.com/consensys/gnark-crypto v0.18.0
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a
github.com/ethereum/go-verkle v0.2.2
github.com/holiman/uint256 v1.3.2
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.10.0
golang.org/x/crypto v0.36.0
)
require (
code.wuban.net.cn/cmpchain/ethcrypto v0.0.0-20250707071006-5c3f8f42b6ad // indirect
github.com/bits-and-blooms/bitset v1.20.0 // indirect
github.com/consensys/gnark-crypto v0.18.0 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
github.com/crate-crypto/go-kzg-4844 v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4 // indirect
github.com/ethereum/go-verkle v0.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/supranational/blst v0.3.14 // indirect
golang.org/x/crypto v0.36.0 // indirect
golang.org/x/sync v0.15.0 // indirect
golang.org/x/sys v0.33.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
......
code.wuban.net.cn/cmpchain/ethcrypto v0.0.0-20250707002024-1f73f3d61c24 h1:yfcvA4ma+sn2LaUSDKEqlLCqc8O38kRNzZX022FRFEA=
code.wuban.net.cn/cmpchain/ethcrypto v0.0.0-20250707002024-1f73f3d61c24/go.mod h1:yA5sSeNbmo4+xVQ5P0/5xAA/jh8eP3CYB9M+sGn3llM=
code.wuban.net.cn/cmpchain/ethcrypto v0.0.0-20250707071006-5c3f8f42b6ad h1:3oJWA4OyqocLv8uwSV47wba6+ZX+Pq7EBI4kolp+RbI=
code.wuban.net.cn/cmpchain/ethcrypto v0.0.0-20250707071006-5c3f8f42b6ad/go.mod h1:yA5sSeNbmo4+xVQ5P0/5xAA/jh8eP3CYB9M+sGn3llM=
github.com/bits-and-blooms/bitset v1.20.0 h1:2F+rfL86jE2d/bmw7OhqUg2Sj/1rURkBn3MdfoPyRVU=
github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8=
github.com/consensys/gnark-crypto v0.18.0 h1:vIye/FqI50VeAr0B3dx+YjeIvmc3LWz4yEfbWBpTUf0=
github.com/consensys/gnark-crypto v0.18.0/go.mod h1:L3mXGFTe1ZN+RSJ+CLjUt9x7PNdx8ubaYfDROyp2Z8c=
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c h1:uQYC5Z1mdLRPrZhHjHxufI8+2UG/i25QG92j0Er9p6I=
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c/go.mod h1:geZJZH3SzKCqnz5VT0q/DyIG/tvu/dZk+VIfXicupJs=
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a h1:W8mUrRp6NOVl3J+MYp5kPMoUZPp7aOYHtaua31lwRHg=
github.com/crate-crypto/go-ipa v0.0.0-20240724233137-53bbb0ceb27a/go.mod h1:sTwzHBvIzm2RfVCGNEBZgRyjwK40bVoun3ZnGOCafNM=
github.com/crate-crypto/go-kzg-4844 v1.1.0 h1:EN/u9k2TF6OWSHrCCDBBU6GLNMq88OspHHlMnHfoyU4=
github.com/crate-crypto/go-kzg-4844 v1.1.0/go.mod h1:JolLjpSff1tCCJKaJx4psrlEdlXuJEC996PL3tTAFks=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4 h1:B2mpK+MNqgPqk2/KNi1LbqwtZDy5F7iy0mynQiBr8VA=
github.com/ethereum/c-kzg-4844/bindings/go v0.0.0-20230126171313-363c7d7593b4/go.mod h1:y4GA2JbAUama1S4QwYjC2hefgGLU8Ul0GMtL/ADMF1c=
github.com/ethereum/go-verkle v0.2.2 h1:I2W0WjnrFUIzzVPwm8ykY+7pL2d4VhlsePn4j7cnFk8=
github.com/ethereum/go-verkle v0.2.2/go.mod h1:M3b90YRnzqKyyzBEWJGqj8Qff4IDeXnzFw0P9bFw3uk=
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA=
github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
github.com/leanovate/gopter v0.2.11 h1:vRjThO1EKPb/1NsDXuDrzldR28RLkBflWYcU9CvzWu4=
github.com/leanovate/gopter v0.2.11/go.mod h1:aK3tzZP/C+p1m3SPRE4SYZFGP7jjkuSI4f7Xvpt0S9c=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
......@@ -47,46 +39,18 @@ github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOf
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/supranational/blst v0.3.14 h1:xNMoHRJOTwMn63ip6qoWJ2Ymgvj7E2b9jY2FAwY+qRo=
github.com/supranational/blst v0.3.14/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
......@@ -17,10 +17,10 @@
package stateless
import (
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
"io"
"code.wuban.net.cn/cmpchain/ethcrypto/rlp"
"code.wuban.net.cn/cmpchain/ethtracer/types"
)
// toExtWitness converts our internal witness representation to the consensus one.
......@@ -70,7 +70,7 @@ func (w *Witness) DecodeRLP(s *rlp.Stream) error {
// extWitness is a witness RLP encoding for transferring across clients.
type extWitness struct {
Headers []*types.Header
Headers []*evmtypes.Header
Codes [][]byte
State [][]byte
}
......@@ -17,28 +17,27 @@
package stateless
import (
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
"errors"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"maps"
"slices"
"sync"
"code.wuban.net.cn/cmpchain/ethtracer/types"
)
// HeaderReader is an interface to pull in headers in place of block hashes for
// the witness.
type HeaderReader interface {
// GetHeader retrieves a block header from the database by hash and number,
GetHeader(hash metatypes.Hash, number uint64) *types.Header
GetHeader(hash metatypes.Hash, number uint64) *evmtypes.Header
}
// Witness encompasses the state required to apply a set of transactions and
// derive a post state/receipt root.
type Witness struct {
context *types.Header // Header to which this witness belongs to, with rootHash and receiptHash zeroed out
context *evmtypes.Header // Header to which this witness belongs to, with rootHash and receiptHash zeroed out
Headers []*types.Header // Past headers in reverse order (0=parent, 1=parent's-parent, etc). First *must* be set.
Headers []*evmtypes.Header // Past headers in reverse order (0=parent, 1=parent's-parent, etc). First *must* be set.
Codes map[string]struct{} // Set of bytecodes ran or accessed
State map[string]struct{} // Set of MPT state trie nodes (account and storage together)
......@@ -47,12 +46,12 @@ type Witness struct {
}
// NewWitness creates an empty witness ready for population.
func NewWitness(context *types.Header, chain HeaderReader) (*Witness, error) {
func NewWitness(context *evmtypes.Header, chain HeaderReader) (*Witness, error) {
// When building witnesses, retrieve the parent header, which will *always*
// be included to act as a trustless pre-root hash container
var headers []*types.Header
var headers []*evmtypes.Header
if chain != nil {
parent := chain.GetHeader(context.Parent(), context.Number().Uint64()-1)
parent := chain.GetHeader(context.ParentHash, context.Number.Uint64()-1)
if parent == nil {
return nil, errors.New("failed to retrieve parent header")
}
......@@ -73,9 +72,9 @@ func NewWitness(context *types.Header, chain HeaderReader) (*Witness, error) {
// the chain to cover the block being added.
func (w *Witness) AddBlockHash(number uint64) {
// Keep pulling in headers until this hash is populated
for int(w.context.Number().Uint64()-number) > len(w.Headers) {
for int(w.context.Number.Uint64()-number) > len(w.Headers) {
tail := w.Headers[len(w.Headers)-1]
w.Headers = append(w.Headers, w.chain.GetHeader(tail.Parent(), tail.Number().Uint64()-1))
w.Headers = append(w.Headers, w.chain.GetHeader(tail.ParentHash, tail.Number.Uint64()-1))
}
}
......@@ -108,7 +107,7 @@ func (w *Witness) Copy() *Witness {
chain: w.chain,
}
if w.context != nil {
cpy.context = types.CopyHeader(w.context)
cpy.context = evmtypes.CopyHeader(w.context)
}
return cpy
}
......@@ -118,5 +117,5 @@ func (w *Witness) Copy() *Witness {
// Note, this method will panic in case of a bad witness (but RLP decoding will
// sanitize it and fail before that).
func (w *Witness) Root() metatypes.Hash {
return w.Headers[0].Root()
return w.Headers[0].Root
}
......@@ -25,12 +25,12 @@
package tracing
import (
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/CaduceusMetaverseProtocol/MetaTypes/types/coretype"
metacore "github.com/CaduceusMetaverseProtocol/MetaTypes/types/coretype"
"math/big"
"code.wuban.net.cn/cmpchain/ethtracer/params"
"code.wuban.net.cn/cmpchain/ethtracer/types"
"github.com/holiman/uint256"
)
......@@ -71,9 +71,9 @@ type VMContext struct {
// BlockEvent is emitted upon tracing an incoming block.
// It contains the block as well as consensus related information.
type BlockEvent struct {
Block *types.Block
Finalized *types.Header
Safe *types.Header
Block *evmtypes.Block
Finalized *evmtypes.Header
Safe *evmtypes.Header
}
type (
......@@ -84,10 +84,10 @@ type (
// TxStartHook is called before the execution of a transaction starts.
// Call simulations don't come with a valid signature. `from` field
// to be used for address of the caller.
TxStartHook = func(vm *VMContext, tx *types.Transaction, from metatypes.Address)
TxStartHook = func(vm *VMContext, tx *evmtypes.Transaction, from metatypes.Address)
// TxEndHook is called after the execution of a transaction ends.
TxEndHook = func(receipt *types.Receipt, err error)
TxEndHook = func(receipt *evmtypes.Receipt, err error)
// EnterHook is invoked when the processing of a message starts.
//
......@@ -140,7 +140,7 @@ type (
SkippedBlockHook = func(event BlockEvent)
// GenesisBlockHook is called when the genesis block is being processed.
GenesisBlockHook = func(genesis *types.Block, alloc coretype.GenesisAccount)
GenesisBlockHook = func(genesis *evmtypes.Block, alloc metacore.GenesisAccount)
// OnSystemCallStartHook is called when a system call is about to be executed. Today,
// this hook is invoked when the EIP-4788 system call is about to be executed to set the
......@@ -182,7 +182,7 @@ type (
StorageChangeHook = func(addr metatypes.Address, slot metatypes.Hash, prev, new metatypes.Hash)
// LogHook is called when a log is emitted.
LogHook = func(log *types.Log)
LogHook = func(log *evmtypes.Log)
// BlockHashReadHook is called when EVM reads the blockhash of a block.
BlockHashReadHook = func(blockNumber uint64, hash metatypes.Hash)
......
......@@ -17,10 +17,10 @@
package tracing
import (
"code.wuban.net.cn/cmpchain/ethtracer/evm/evmtypes"
"fmt"
"math/big"
"code.wuban.net.cn/cmpchain/ethtracer/types"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
)
......@@ -112,7 +112,7 @@ func (j *journal) popRevision() {
}
// OnTxEnd resets the journal since each transaction has its own EVM call stack.
func (j *journal) OnTxEnd(receipt *types.Receipt, err error) {
func (j *journal) OnTxEnd(receipt *evmtypes.Receipt, err error) {
j.reset()
if j.hooks.OnTxEnd != nil {
j.hooks.OnTxEnd(receipt, err)
......
package types
import (
basetype "github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/base/v1"
metatypes "github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"math/big"
)
var (
......@@ -12,69 +10,70 @@ var (
EmptyCodeHash = metatypes.HexToHash("c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470")
)
type Block struct {
*basetype.MetaBlock
}
type Header struct {
*basetype.MetaBlockHeader
}
func (h *Header) Number() *big.Int {
return h.BlockNumber.GetInt()
}
func (h *Header) Parent() metatypes.Hash {
return *h.ParentHash
}
func (h *Header) Root() metatypes.Hash {
return *h.StateRoot
}
type Transaction struct {
*basetype.MetaProofTx
}
type Receipt struct {
*basetype.MetaReceipt
}
type Log struct {
*basetype.MetaTxLog
}
func NewLog(addr metatypes.Address, topics []metatypes.Hash, data []byte, number uint64) *Log {
l := &Log{
MetaTxLog: &basetype.MetaTxLog{
Address: new(metatypes.Address),
Topics: make([]*basetype.MetaTopic, len(topics)),
Data: data,
BlockNumber: number,
},
}
l.Address.SetBytes(addr.Bytes())
for i, topic := range topics {
l.Topics[i] = &basetype.MetaTopic{
Topic: new(metatypes.Hash),
}
l.Topics[i].Topic.SetBytes(topic.Bytes())
}
return l
}
//type GenesisAlloc struct {
// *basetype.MetaGenesisAlloc
//
//type Block struct {
// *basetype.MetaBlock
//}
//
//type Header struct {
// *basetype.MetaBlockHeader
//}
//
//func (h *Header) Number() *big.Int {
// return h.BlockNumber.GetInt()
//}
//
//func (h *Header) Parent() metatypes.Hash {
// return *h.ParentHash
//}
//func (h *Header) Root() metatypes.Hash {
// return *h.StateRoot
//}
//
//type Transaction struct {
// *basetype.MetaProofTx
//}
//
//type Receipt struct {
// *basetype.MetaReceipt
//}
//
//type Log struct {
// *basetype.MetaTxLog
//}
//
//func NewLog(addr metatypes.Address, topics []metatypes.Hash, data []byte, number uint64) *Log {
// l := &Log{
// MetaTxLog: &basetype.MetaTxLog{
// Address: new(metatypes.Address),
// Topics: make([]*basetype.MetaTopic, len(topics)),
// Data: data,
// BlockNumber: number,
// },
// }
// l.Address.SetBytes(addr.Bytes())
// for i, topic := range topics {
// l.Topics[i] = &basetype.MetaTopic{
// Topic: new(metatypes.Hash),
// }
// l.Topics[i].Topic.SetBytes(topic.Bytes())
// }
// return l
//}
//
////type GenesisAlloc struct {
//// *basetype.MetaGenesisAlloc
////}
//
//func CopyHeader(h *Header) *Header {
// return &Header{
// MetaBlockHeader: &basetype.MetaBlockHeader{
// BlockNumber: h.BlockNumber,
// ParentHash: h.ParentHash,
// Timestamp: h.Timestamp,
// Miner: h.Miner,
// GasLimit: h.GasLimit,
// GasUsed: h.GasUsed,
// },
// }
//}
func CopyHeader(h *Header) *Header {
return &Header{
MetaBlockHeader: &basetype.MetaBlockHeader{
BlockNumber: h.BlockNumber,
ParentHash: h.ParentHash,
Timestamp: h.Timestamp,
Miner: h.Miner,
GasLimit: h.GasLimit,
GasUsed: h.GasUsed,
},
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment