Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] #440

Closed
wants to merge 48 commits into from
Closed

[wip] #440

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
543e71e
remove ethdb
darioush Oct 24, 2023
bee5a18
fix codebase
darioush Oct 24, 2023
ad39ea6
go.mod
darioush Dec 28, 2023
026d8b3
minimize cosmetic diffs
darioush Dec 28, 2023
8a126c6
link an accessible dependency
darioush Dec 28, 2023
4fc5320
reduce vmerrs diff
darioush Dec 28, 2023
bc797a1
minor alignments
darioush Dec 28, 2023
d6e5108
refactor: move AllowUnfinalizedQueries out of vm.Config
darioush Dec 28, 2023
6ed7aa9
Merge branch 'refactor-allow-unfinalized' of github.com:ava-labs/core…
darioush Dec 28, 2023
df8c709
remove unneeded file
darioush Dec 28, 2023
151f592
add vanilla geth
darioush Dec 28, 2023
b5f7d25
move gas table modifications to gas_table_ext.go
darioush Dec 28, 2023
dbfb2a1
patch geth import script
darioush Dec 28, 2023
b3c5ec9
align comment
darioush Dec 29, 2023
a6fb29b
exploring: path for custom precompiles
darioush Dec 29, 2023
97a0fb0
wip
darioush Dec 29, 2023
73b14d2
Remove state_prefetcher.go
darioush Jan 2, 2024
9a68df8
Merge branch 'remove-state-prefetcher' of github.com:ava-labs/coreth …
darioush Jan 2, 2024
b4133ae
core/types: reudce diff
darioush Jan 3, 2024
31e28d9
core/types: tx refactor
darioush Jan 3, 2024
faf8cd6
minimize diff
darioush Jan 3, 2024
5766c13
reuduce diff
darioush Jan 3, 2024
5ada17d
minimize more diffs
darioush Jan 6, 2024
9eccb35
reduce diff
darioush Jan 6, 2024
e4b29b7
reduce diff
darioush Jan 6, 2024
824082d
rename interfaces --> ethereum
darioush Jan 6, 2024
7c1c578
fix rename
darioush Jan 6, 2024
9924cb5
minimize more diff
darioush Jan 6, 2024
5d845bf
Merge branch 'master' of github.com:ava-labs/coreth into coreth-000
darioush Jan 6, 2024
c80d622
temporary exclude from lint
darioush Jan 6, 2024
caaa0bb
fix eth/filters
darioush Jan 6, 2024
cfcbc3d
fix template
darioush Jan 6, 2024
e540c18
reduce diffs
darioush Jan 6, 2024
d6ccd24
use `core.NewEVM`
darioush Jan 8, 2024
8f884ed
wip
darioush Jan 9, 2024
771172e
add jt
darioush Jan 9, 2024
2367fc4
remove core/vm
darioush Jan 9, 2024
055150c
switch url for core/vm
darioush Jan 9, 2024
a583398
fix linter
darioush Jan 9, 2024
133f31b
put this back
darioush Jan 9, 2024
47268d6
try this e2e
darioush Jan 9, 2024
9fc30ba
unused
darioush Jan 9, 2024
01436f1
cosmetic alignments
darioush Jan 9, 2024
13fc41f
handle eth/tracers/{js,logger,native}
darioush Jan 9, 2024
0df2249
Merge branches '002-ethdb-align' and 'master' of github.com:ava-labs/…
darioush Jan 9, 2024
36ef34e
merge fixes
darioush Jan 9, 2024
fd7aab7
missed this file
darioush Jan 9, 2024
022e3ef
Merge branch '002-ethdb-align' of github.com:ava-labs/coreth into cor…
darioush Jan 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
119 changes: 0 additions & 119 deletions accounts/abi/abi.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
// (c) 2019-2020, Ava Labs, Inc.
//
// This file is a derived work, based on the go-ethereum library whose original
// notices appear below.
//
// It is distributed under a license compatible with the licensing terms of the
// original code from which it is derived.
//
// Much love to the original authors for their work.
// **********
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
Expand Down Expand Up @@ -91,91 +81,6 @@ func (abi ABI) Pack(name string, args ...interface{}) ([]byte, error) {
return append(method.ID, arguments...), nil
}

// PackEvent packs the given event name and arguments to conform the ABI.
// Returns the topics for the event including the event signature (if non-anonymous event) and
// hashes derived from indexed arguments and the packed data of non-indexed args according to
// the event ABI specification.
// The order of arguments must match the order of the event definition.
// https://docs.soliditylang.org/en/v0.8.17/abi-spec.html#indexed-event-encoding.
// Note: PackEvent does not support array (fixed or dynamic-size) or struct types.
func (abi ABI) PackEvent(name string, args ...interface{}) ([]common.Hash, []byte, error) {
event, exist := abi.Events[name]
if !exist {
return nil, nil, fmt.Errorf("event '%s' not found", name)
}
if len(args) != len(event.Inputs) {
return nil, nil, fmt.Errorf("event '%s' unexpected number of inputs %d", name, len(args))
}

var (
nonIndexedInputs = make([]interface{}, 0)
indexedInputs = make([]interface{}, 0)
nonIndexedArgs Arguments
indexedArgs Arguments
)

for i, arg := range event.Inputs {
if arg.Indexed {
indexedArgs = append(indexedArgs, arg)
indexedInputs = append(indexedInputs, args[i])
} else {
nonIndexedArgs = append(nonIndexedArgs, arg)
nonIndexedInputs = append(nonIndexedInputs, args[i])
}
}

packedArguments, err := nonIndexedArgs.Pack(nonIndexedInputs...)
if err != nil {
return nil, nil, err
}
topics := make([]common.Hash, 0, len(indexedArgs)+1)
if !event.Anonymous {
topics = append(topics, event.ID)
}
indexedTopics, err := PackTopics(indexedInputs)
if err != nil {
return nil, nil, err
}

return append(topics, indexedTopics...), packedArguments, nil
}

// PackOutput packs the given [args] as the output of given method [name] to conform the ABI.
// This does not include method ID.
func (abi ABI) PackOutput(name string, args ...interface{}) ([]byte, error) {
// Fetch the ABI of the requested method
method, exist := abi.Methods[name]
if !exist {
return nil, fmt.Errorf("method '%s' not found", name)
}
arguments, err := method.Outputs.Pack(args...)
if err != nil {
return nil, err
}
return arguments, nil
}

// getInputs gets input arguments of the given [name] method.
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 useStrictMode && len(data)%32 != 0 {
return nil, fmt.Errorf("abi: improperly formatted input: %s - Bytes: [%+v]", string(data), data)
}
args = method.Inputs
}
if event, ok := abi.Events[name]; ok {
args = event.Inputs
}
if args == nil {
return nil, fmt.Errorf("abi: could not locate named method or event: %s", name)
}
return args, nil
}

// getArguments gets output arguments of the given [name] method.
func (abi ABI) getArguments(name string, data []byte) (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
Expand All @@ -195,15 +100,6 @@ func (abi ABI) getArguments(name string, data []byte) (Arguments, error) {
return args, nil
}

// UnpackInput unpacks the input according to the ABI specification.
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
}
return args.Unpack(data)
}

// Unpack unpacks the output according to the abi specification.
func (abi ABI) Unpack(name string, data []byte) ([]interface{}, error) {
args, err := abi.getArguments(name, data)
Expand All @@ -213,21 +109,6 @@ func (abi ABI) Unpack(name string, data []byte) ([]interface{}, error) {
return args.Unpack(data)
}

// 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, useStrictMode bool) error {
args, err := abi.getInputs(name, data, useStrictMode)
if err != nil {
return err
}
unpacked, err := args.Unpack(data)
if err != nil {
return err
}
return args.Copy(v, unpacked)
}

// UnpackIntoInterface unpacks the output 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)
Expand Down
115 changes: 115 additions & 0 deletions accounts/abi/abi_ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package abi

import (
"fmt"

"github.com/ethereum/go-ethereum/common"
)

// PackEvent packs the given event name and arguments to conform the ABI.
// Returns the topics for the event including the event signature (if non-anonymous event) and
// hashes derived from indexed arguments and the packed data of non-indexed args according to
// the event ABI specification.
// The order of arguments must match the order of the event definition.
// https://docs.soliditylang.org/en/v0.8.17/abi-spec.html#indexed-event-encoding.
// Note: PackEvent does not support array (fixed or dynamic-size) or struct types.
func (abi ABI) PackEvent(name string, args ...interface{}) ([]common.Hash, []byte, error) {
event, exist := abi.Events[name]
if !exist {
return nil, nil, fmt.Errorf("event '%s' not found", name)
}
if len(args) != len(event.Inputs) {
return nil, nil, fmt.Errorf("event '%s' unexpected number of inputs %d", name, len(args))
}

var (
nonIndexedInputs = make([]interface{}, 0)
indexedInputs = make([]interface{}, 0)
nonIndexedArgs Arguments
indexedArgs Arguments
)

for i, arg := range event.Inputs {
if arg.Indexed {
indexedArgs = append(indexedArgs, arg)
indexedInputs = append(indexedInputs, args[i])
} else {
nonIndexedArgs = append(nonIndexedArgs, arg)
nonIndexedInputs = append(nonIndexedInputs, args[i])
}
}

packedArguments, err := nonIndexedArgs.Pack(nonIndexedInputs...)
if err != nil {
return nil, nil, err
}
topics := make([]common.Hash, 0, len(indexedArgs)+1)
if !event.Anonymous {
topics = append(topics, event.ID)
}
indexedTopics, err := PackTopics(indexedInputs)
if err != nil {
return nil, nil, err
}

return append(topics, indexedTopics...), packedArguments, nil
}

// PackOutput packs the given [args] as the output of given method [name] to conform the ABI.
// This does not include method ID.
func (abi ABI) PackOutput(name string, args ...interface{}) ([]byte, error) {
// Fetch the ABI of the requested method
method, exist := abi.Methods[name]
if !exist {
return nil, fmt.Errorf("method '%s' not found", name)
}
arguments, err := method.Outputs.Pack(args...)
if err != nil {
return nil, err
}
return arguments, nil
}

// getInputs gets input arguments of the given [name] method.
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 useStrictMode && len(data)%32 != 0 {
return nil, fmt.Errorf("abi: improperly formatted input: %s - Bytes: [%+v]", string(data), data)
}
args = method.Inputs
}
if event, ok := abi.Events[name]; ok {
args = event.Inputs
}
if args == nil {
return nil, fmt.Errorf("abi: could not locate named method or event: %s", name)
}
return args, nil
}

// UnpackInput unpacks the input according to the ABI specification.
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
}
return args.Unpack(data)
}

// 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, useStrictMode bool) error {
args, err := abi.getInputs(name, data, useStrictMode)
if err != nil {
return err
}
unpacked, err := args.Unpack(data)
if err != nil {
return err
}
return args.Copy(v, unpacked)
}
96 changes: 96 additions & 0 deletions accounts/abi/abi_extra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"testing"

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

Expand Down Expand Up @@ -109,3 +110,98 @@ func TestPackOutput(t *testing.T) {
require.Len(t, vals, 1)
require.True(t, vals[0].(bool))
}

func TestABI_PackEvent(t *testing.T) {
tests := []struct {
name string
json string
event string
args []interface{}
expectedTopics []common.Hash
expectedData []byte
}{
{
name: "received",
json: `[
{"type":"event","name":"received","anonymous":false,"inputs":[
{"indexed":false,"name":"sender","type":"address"},
{"indexed":false,"name":"amount","type":"uint256"},
{"indexed":false,"name":"memo","type":"bytes"}
]
}]`,
event: "received(address,uint256,bytes)",
args: []interface{}{
common.HexToAddress("0x376c47978271565f56DEB45495afa69E59c16Ab2"),
big.NewInt(1),
[]byte{0x88},
},
expectedTopics: []common.Hash{
common.HexToHash("0x75fd880d39c1daf53b6547ab6cb59451fc6452d27caa90e5b6649dd8293b9eed"),
},
expectedData: common.Hex2Bytes("000000000000000000000000376c47978271565f56deb45495afa69e59c16ab20000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000018800000000000000000000000000000000000000000000000000000000000000"),
},
{
name: "received",
json: `[
{"type":"event","name":"received","anonymous":true,"inputs":[
{"indexed":false,"name":"sender","type":"address"},
{"indexed":false,"name":"amount","type":"uint256"},
{"indexed":false,"name":"memo","type":"bytes"}
]
}]`,
event: "received(address,uint256,bytes)",
args: []interface{}{
common.HexToAddress("0x376c47978271565f56DEB45495afa69E59c16Ab2"),
big.NewInt(1),
[]byte{0x88},
},
expectedTopics: []common.Hash{},
expectedData: common.Hex2Bytes("000000000000000000000000376c47978271565f56deb45495afa69e59c16ab20000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000018800000000000000000000000000000000000000000000000000000000000000"),
}, {
name: "Transfer",
json: `[
{ "constant": true, "inputs": [], "name": "name", "outputs": [ { "name": "", "type": "string" } ], "payable": false, "stateMutability": "view", "type": "function" },
{ "constant": false, "inputs": [ { "name": "_spender", "type": "address" }, { "name": "_value", "type": "uint256" } ], "name": "approve", "outputs": [ { "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" },
{ "constant": true, "inputs": [], "name": "totalSupply", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" },
{ "constant": false, "inputs": [ { "name": "_from", "type": "address" }, { "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" } ], "name": "transferFrom", "outputs": [ { "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" },
{ "constant": true, "inputs": [], "name": "decimals", "outputs": [ { "name": "", "type": "uint8" } ], "payable": false, "stateMutability": "view", "type": "function" },
{ "constant": true, "inputs": [ { "name": "_owner", "type": "address" } ], "name": "balanceOf", "outputs": [ { "name": "balance", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" },
{ "constant": true, "inputs": [], "name": "symbol", "outputs": [ { "name": "", "type": "string" } ], "payable": false, "stateMutability": "view", "type": "function" },
{ "constant": false, "inputs": [ { "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" } ], "name": "transfer", "outputs": [ { "name": "", "type": "bool" } ], "payable": false, "stateMutability": "nonpayable", "type": "function" },
{ "constant": true, "inputs": [ { "name": "_owner", "type": "address" }, { "name": "_spender", "type": "address" } ], "name": "allowance", "outputs": [ { "name": "", "type": "uint256" } ], "payable": false, "stateMutability": "view", "type": "function" },
{ "payable": true, "stateMutability": "payable", "type": "fallback" },
{ "anonymous": false, "inputs": [ { "indexed": true, "name": "owner", "type": "address" }, { "indexed": true, "name": "spender", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" } ], "name": "Approval", "type": "event" },
{ "anonymous": false, "inputs": [ { "indexed": true, "name": "from", "type": "address" }, { "indexed": true, "name": "to", "type": "address" }, { "indexed": false, "name": "value", "type": "uint256" } ], "name": "Transfer", "type": "event" }
]`,
event: "Transfer(address,address,uint256)",
args: []interface{}{
common.HexToAddress("0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC"),
common.HexToAddress("0x376c47978271565f56DEB45495afa69E59c16Ab2"),
big.NewInt(100),
},
expectedTopics: []common.Hash{
common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"),
common.HexToHash("0x0000000000000000000000008db97c7cece249c2b98bdc0226cc4c2a57bf52fc"),
common.HexToHash("0x000000000000000000000000376c47978271565f56deb45495afa69e59c16ab2"),
},
expectedData: common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000064"),
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
abi, err := JSON(strings.NewReader(test.json))
if err != nil {
t.Error(err)
}

topics, data, err := abi.PackEvent(test.name, test.args...)
if err != nil {
t.Fatal(err)
}

assert.EqualValues(t, test.expectedTopics, topics)
assert.EqualValues(t, test.expectedData, data)
})
}
}
Loading
Loading