-
Notifications
You must be signed in to change notification settings - Fork 223
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: use libevm (params, core/vm) #1335
base: master
Are you sure you want to change the base?
Changes from 1 commit
6d60741
d999563
1c7e25b
a119516
25bb446
c371a3a
9b27ebe
784e2e6
a8a5c80
d74cea6
ed1165b
e1088b1
846f52a
932967d
053af95
44db6c7
cd5adc9
70659d3
5d5fb59
07203b0
99c1b70
e8febb8
04338c7
a5a43cc
4a41e81
5049989
2a46ead
672f54e
7b8ec21
f30f450
dc4b361
5038b15
dad843a
0fe10ff
5b073ad
34a17a6
73b5559
61b1694
8d2493f
12cd83e
20854a1
e9ee414
61eb933
28caecc
86cdfbe
f1d77d2
7bfbe08
27a8bfb
d72ff25
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,11 @@ import ( | |
"github.com/ava-labs/subnet-evm/consensus" | ||
"github.com/ava-labs/subnet-evm/consensus/misc/eip4844" | ||
"github.com/ava-labs/subnet-evm/core/types" | ||
"github.com/ava-labs/subnet-evm/params" | ||
"github.com/ava-labs/subnet-evm/predicate" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/core/vm" | ||
"github.com/ethereum/go-ethereum/libevm" | ||
"github.com/ethereum/go-ethereum/log" | ||
"github.com/holiman/uint256" | ||
) | ||
|
@@ -47,6 +49,8 @@ type ChainContext interface { | |
|
||
// GetHeader returns the header corresponding to the hash/number argument pair. | ||
GetHeader(common.Hash, uint64) *types.Header | ||
|
||
Config() *params.ChainConfig | ||
} | ||
|
||
// NewEVMBlockContext creates a new context for use in the EVM. | ||
|
@@ -73,15 +77,16 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common | |
// in header.Extra. | ||
// This function is used to create a BlockContext when the header Extra data is not fully formed yet and it's more efficient to pass in predicateResults | ||
// directly rather than re-encode the latest results when executing each individaul transaction. | ||
func NewEVMBlockContextWithPredicateResults(header *types.Header, chain ChainContext, author *common.Address, predicateResults *predicate.Results) vm.BlockContext { | ||
func NewEVMBlockContextWithPredicateResults(header *types.Header, chain ChainContext, author *common.Address, predicateResults libevm.PredicateResults) vm.BlockContext { | ||
return newEVMBlockContext(header, chain, author, predicateResults) | ||
} | ||
|
||
func newEVMBlockContext(header *types.Header, chain ChainContext, author *common.Address, predicateResults *predicate.Results) vm.BlockContext { | ||
func newEVMBlockContext(header *types.Header, chain ChainContext, author *common.Address, predicateResults libevm.PredicateResults) vm.BlockContext { | ||
var ( | ||
beneficiary common.Address | ||
baseFee *big.Int | ||
blobBaseFee *big.Int | ||
random *common.Hash | ||
) | ||
|
||
// If we don't have an explicit author (i.e. not mining), extract from the header | ||
|
@@ -96,6 +101,14 @@ func newEVMBlockContext(header *types.Header, chain ChainContext, author *common | |
if header.ExcessBlobGas != nil { | ||
blobBaseFee = eip4844.CalcBlobFee(*header.ExcessBlobGas) | ||
} | ||
|
||
// Durango enables the Shanghai upgrade of eth, which takes place after the | ||
// Merge upgrade. | ||
isDurango := params.GetExtra(chain.Config()).IsDurango(header.Time) | ||
if isDurango { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we rather introduce shangai (could be a different PR) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is avalanche specific, so I think it is better to activate it via durango. |
||
random = new(common.Hash) | ||
random.SetBytes(header.Difficulty.Bytes()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't this potentially dangerous as we have activated Durango without this field set? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should not be dangerous since we will not serialize this value back. |
||
} | ||
return vm.BlockContext{ | ||
CanTransfer: CanTransfer, | ||
Transfer: Transfer, | ||
|
@@ -108,6 +121,7 @@ func newEVMBlockContext(header *types.Header, chain ChainContext, author *common | |
BaseFee: baseFee, | ||
BlobBaseFee: blobBaseFee, | ||
GasLimit: header.GasLimit, | ||
Random: random, | ||
} | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// (c) 2024, 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. | ||
// | ||
// 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 tests | ||
|
||
import ( | ||
"github.com/ava-labs/subnet-evm/core" | ||
"github.com/ava-labs/subnet-evm/params" | ||
) | ||
|
||
type withChainConfig struct { | ||
core.ChainContext | ||
config *params.ChainConfig | ||
} | ||
|
||
func (w withChainConfig) Config() *params.ChainConfig { | ||
return w.config | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upstream avoids this dependency here (on chain config/rules) by checking if Difficulty is 0,
but we cannot rely on that because we already made blocks with difficulty set to 1.