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

Morph scroll v4.2.2 #16

Merged
merged 23 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
910d4f1
feat(trace): add storage proof about l1fee (baseFee, overhead, scalar…
noel2004 May 18, 2023
1094569
feat: enable eip and update check (#335)
NazariiDenha May 19, 2023
149419c
fix(trace): deletion proof missed path terminated by empty node (#330)
noel2004 May 22, 2023
a89ab83
fix(API): use `hexutil.Big` for `l1Fee` in `GetTransactionReceipt` (#…
mask-pp May 22, 2023
2f70857
refactor(config): moved fee vault addr to rollup config (#341)
rrzhang139 May 22, 2023
0c182f1
feat(abigen): add `--contract` flag to specify a given contract (#334)
mask-pp May 22, 2023
9f981c5
build(github): update github action yaml (#347)
0xmountaintop May 24, 2023
fb570dc
ci(github): update pull request template (#349)
0xmountaintop May 24, 2023
334892a
Return error for disabled precompile calls (#337)
Thegaram May 24, 2023
060815e
feat: delay Archimedes on Alpha by a week (#342)
Thegaram May 24, 2023
31b754e
Fix transaction DA cost under-estimation (#332)
Thegaram May 24, 2023
ad43d0e
feat(block_validator): check payload size during block validation (#322)
rrzhang139 May 24, 2023
74725fb
test(zkTrie): add deletion test in account update unit test (#344)
colinlyguo May 25, 2023
9b943f3
fix: add missing term when merging two deletion proofs (#353)
noel2004 Jun 1, 2023
1f167bd
fix(ethclient): support WithdrawalsHash in Scroll Go SDK (#354)
rrzhang139 Jun 5, 2023
4867699
fix(tracing): fix ZktrieTracer race condition (#356)
noel2004 Jun 7, 2023
983d630
feat: Sync and relay L1 messages (#350)
Thegaram Jun 7, 2023
4e0daeb
fix(trace): change l1Fee type from uint64 to *big.Int (#360)
Thegaram Jun 9, 2023
f055f50
feat: update l1fee calculation (#351)
0xmountaintop Jun 13, 2023
b5e8d12
feat: return keccak(chainId || height) for BLOCKHASH opcode (#359)
rrzhang139 Jun 14, 2023
43be9a6
feat(abigen): Add flag let be able to add user tmpl file. (#362)
mask-pp Jun 19, 2023
b14a402
fix: improve L1Message RPC encoding (#368)
Thegaram Jun 19, 2023
1d91b84
merge commits under scroll tag v4.2.2
FletcherMan Jun 26, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/scroll-tech/go-ethereum/event"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rollup/fees"
"github.com/scroll-tech/go-ethereum/rpc"
)

Expand Down Expand Up @@ -638,8 +639,13 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
// about the transaction and calling mechanisms.
vmEnv := vm.NewEVM(evmContext, txContext, stateDB, b.config, vm.Config{NoBaseFee: true})
gasPool := new(core.GasPool).AddGas(math.MaxUint64)
signer := types.MakeSigner(b.blockchain.Config(), head.Number)
l1DataFee, err := fees.EstimateL1DataFeeForMessage(msg, head.BaseFee, b.blockchain.Config().ChainID, signer, stateDB)
if err != nil {
return nil, err
}

return core.NewStateTransition(vmEnv, msg, gasPool).TransitionDb()
return core.NewStateTransition(vmEnv, msg, gasPool, l1DataFee).TransitionDb()
}

// SendTransaction updates the pending block to include the given transaction.
Expand Down
7 changes: 7 additions & 0 deletions accounts/abi/bind/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ var tmplSource = map[Lang]string{
LangJava: tmplSourceJava,
}

// SetTmplSource supports this func in order to set special template file.
func SetTmplSource(lang Lang, source string) {
if _, ok := tmplSource[lang]; ok {
tmplSource[lang] = source
}
}

// tmplSourceGo is the Go source template that the generated Go contract binding
// is based on.
const tmplSourceGo = `
Expand Down
14 changes: 14 additions & 0 deletions cmd/abigen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ var (
Name: "contract",
Usage: "Name of the contract to generate the bindings for",
}
tmplFlag = cli.StringFlag{
Name: "tmpl",
Usage: "Template file if a user wants to customize",
}
)

func init() {
Expand All @@ -122,6 +126,7 @@ func init() {
langFlag,
aliasFlag,
contractFlag,
tmplFlag,
}
app.Action = utils.MigrateFlags(abigen)
cli.CommandHelpTemplate = flags.OriginCommandHelpTemplate
Expand Down Expand Up @@ -265,6 +270,15 @@ func abigen(c *cli.Context) error {
aliases[match[1]] = match[2]
}
}
// Set customize template file.
if c.GlobalIsSet(tmplFlag.Name) {
tmplFile := c.GlobalString(tmplFlag.Name)
data, err := os.ReadFile(tmplFile)
if err != nil {
utils.Fatalf("Failed to read template file: %v", err)
}
bind.SetTmplSource(lang, string(data))
}
// Generate the contract binding
code, err := bind.Bind(types, abis, bins, sigs, c.GlobalString(pkgFlag.Name), lang, libs, aliases)
if err != nil {
Expand Down
10 changes: 9 additions & 1 deletion cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rlp"
"github.com/scroll-tech/go-ethereum/rollup/fees"
"github.com/scroll-tech/go-ethereum/trie"
)

Expand Down Expand Up @@ -166,8 +167,15 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
snapshot := statedb.Snapshot()
evm := vm.NewEVM(vmContext, txContext, statedb, chainConfig, vmConfig)

l1DataFee, err := fees.CalculateL1DataFee(tx, statedb)
if err != nil {
log.Info("rejected tx due to fees.CalculateL1DataFee", "index", i, "hash", tx.Hash(), "from", msg.From(), "error", err)
rejectedTxs = append(rejectedTxs, &rejectedTx{i, err.Error()})
continue
}

// (ret []byte, usedGas uint64, failed bool, err error)
msgResult, err := core.ApplyMessage(evm, msg, gaspool)
msgResult, err := core.ApplyMessage(evm, msg, gaspool, l1DataFee)
if err != nil {
statedb.RevertToSnapshot(snapshot)
log.Info("rejected tx", "index", i, "hash", tx.Hash(), "from", msg.From(), "error", err)
Expand Down
1 change: 0 additions & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ var (
utils.GpoIgnoreGasPriceFlag,
utils.MinerNotifyFullFlag,
configFileFlag,
//>>>>>>> scroll/v4.1.0
utils.CatalystFlag,
}

Expand Down
3 changes: 3 additions & 0 deletions core/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ type ChainSideEvent struct {
}

type ChainHeadEvent struct{ Block *types.Block }

// NewL1MsgsEvent is posted when we receive some new messages from L1.
type NewL1MsgsEvent struct{ Count int }
14 changes: 11 additions & 3 deletions core/state_prefetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
package core

import (
"math/big"
"sync/atomic"

"github.com/scroll-tech/go-ethereum/consensus"
"github.com/scroll-tech/go-ethereum/core/state"
"github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/core/vm"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rollup/fees"
)

// statePrefetcher is a basic Prefetcher, which blindly executes a block on top
Expand Down Expand Up @@ -68,7 +70,13 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
return // Also invalid block, bail out
}
statedb.Prepare(tx.Hash(), i)
if err := precacheTransaction(msg, p.config, gaspool, statedb, header, evm); err != nil {

l1DataFee, err := fees.CalculateL1DataFee(tx, statedb)
if err != nil {
return
}

if err = precacheTransaction(msg, p.config, gaspool, statedb, header, evm, l1DataFee); err != nil {
return // Ugh, something went horribly wrong, bail out
}
// If we're pre-byzantium, pre-load trie nodes for the intermediate root
Expand All @@ -85,10 +93,10 @@ func (p *statePrefetcher) Prefetch(block *types.Block, statedb *state.StateDB, c
// precacheTransaction attempts to apply a transaction to the given state database
// and uses the input parameters for its environment. The goal is not to execute
// the transaction successfully, rather to warm up touched data slots.
func precacheTransaction(msg types.Message, config *params.ChainConfig, gaspool *GasPool, statedb *state.StateDB, header *types.Header, evm *vm.EVM) error {
func precacheTransaction(msg types.Message, config *params.ChainConfig, gaspool *GasPool, statedb *state.StateDB, header *types.Header, evm *vm.EVM, l1DataFee *big.Int) error {
// Update the evm with the new transaction context.
evm.Reset(NewEVMTxContext(msg), statedb)
// Add addresses to access list if applicable
_, err := ApplyMessage(evm, msg, gaspool)
_, err := ApplyMessage(evm, msg, gaspool, l1DataFee)
return err
}
10 changes: 8 additions & 2 deletions core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/scroll-tech/go-ethereum/core/vm"
"github.com/scroll-tech/go-ethereum/crypto"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rollup/fees"
)

// StateProcessor is a basic Processor, which takes care of transitioning
Expand Down Expand Up @@ -97,8 +98,13 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
txContext := NewEVMTxContext(msg)
evm.Reset(txContext, statedb)

l1DataFee, err := fees.CalculateL1DataFee(tx, statedb)
if err != nil {
return nil, err
}

// Apply the transaction to the current state (included in the env).
result, err := ApplyMessage(evm, msg, gp)
result, err := ApplyMessage(evm, msg, gp, l1DataFee)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -139,7 +145,7 @@ func applyTransaction(msg types.Message, config *params.ChainConfig, bc ChainCon
receipt.BlockHash = blockHash
receipt.BlockNumber = blockNumber
receipt.TransactionIndex = uint(statedb.TxIndex())
receipt.L1Fee = result.L1Fee
receipt.L1Fee = result.L1DataFee
return receipt, err
}

Expand Down
43 changes: 21 additions & 22 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/scroll-tech/go-ethereum/crypto/codehash"
"github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/params"
"github.com/scroll-tech/go-ethereum/rollup/fees"
)

var emptyKeccakCodeHash = codehash.EmptyKeccakCodeHash
Expand Down Expand Up @@ -65,8 +64,7 @@ type StateTransition struct {
state vm.StateDB
evm *vm.EVM

// l1 rollup fee
l1Fee *big.Int
l1DataFee *big.Int
}

// Message represents a message sent to a contract.
Expand All @@ -90,7 +88,7 @@ type Message interface {
// ExecutionResult includes all output after executing given evm
// message no matter the execution itself is successful or not.
type ExecutionResult struct {
L1Fee *big.Int
L1DataFee *big.Int
UsedGas uint64 // Total used gas but include the refunded gas
Err error // Any error encountered during the execution(listed in core/vm/errors.go)
ReturnData []byte // Returned data from evm(function result or data supplied with revert opcode)
Expand Down Expand Up @@ -183,12 +181,7 @@ func toWordSize(size uint64) uint64 {
}

// NewStateTransition initialises and returns a new state transition object.
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition {
l1Fee := new(big.Int)
if evm.ChainConfig().Scroll.FeeVaultEnabled() {
l1Fee, _ = fees.CalculateL1MsgFee(msg, evm.StateDB)
}

func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool, l1DataFee *big.Int) *StateTransition {
return &StateTransition{
gp: gp,
evm: evm,
Expand All @@ -199,7 +192,7 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
value: msg.Value(),
data: msg.Data(),
state: evm.StateDB,
l1Fee: l1Fee,
l1DataFee: l1DataFee,
}
}

Expand All @@ -210,8 +203,8 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
// the gas used (which includes gas refunds) and an error if it failed. An error always
// indicates a core error meaning that the message would always fail for that particular
// state and would never be accepted within a block.
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) (*ExecutionResult, error) {
return NewStateTransition(evm, msg, gp).TransitionDb()
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool, l1DataFee *big.Int) (*ExecutionResult, error) {
return NewStateTransition(evm, msg, gp, l1DataFee).TransitionDb()
}

// to returns the recipient of the message.
Expand All @@ -227,9 +220,12 @@ func (st *StateTransition) buyGas() error {
mgval = mgval.Mul(mgval, st.gasPrice)

if st.evm.ChainConfig().Scroll.FeeVaultEnabled() {
// always add l1fee, because all tx are L2-to-L1 ATM
log.Debug("Adding L1 fee", "l1_fee", st.l1Fee)
mgval = mgval.Add(mgval, st.l1Fee)
// should be fine to add st.l1DataFee even without `L1MessageTx` check, since L1MessageTx will come with 0 l1DataFee,
// but double check to make sure
if !st.msg.IsL1MessageTx() {
log.Debug("Adding L1DataFee", "l1DataFee", st.l1DataFee)
mgval = mgval.Add(mgval, st.l1DataFee)
}
}

balanceCheck := mgval
Expand All @@ -238,8 +234,11 @@ func (st *StateTransition) buyGas() error {
balanceCheck = balanceCheck.Mul(balanceCheck, st.gasFeeCap)
balanceCheck.Add(balanceCheck, st.value)
if st.evm.ChainConfig().Scroll.FeeVaultEnabled() {
// always add l1fee, because all tx are L2-to-L1 ATM
balanceCheck.Add(balanceCheck, st.l1Fee)
// should be fine to add st.l1DataFee even without `L1MessageTx` check, since L1MessageTx will come with 0 l1DataFee,
// but double check to make sure
if !st.msg.IsL1MessageTx() {
balanceCheck.Add(balanceCheck, st.l1DataFee)
}
}
}
if have, want := st.state.GetBalance(st.msg.From()), balanceCheck; have.Cmp(want) < 0 {
Expand Down Expand Up @@ -393,7 +392,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
// no refunds for l1 messages
if st.msg.IsL1MessageTx() {
return &ExecutionResult{
L1Fee: big.NewInt(0),
L1DataFee: big.NewInt(0),
UsedGas: st.gasUsed(),
Err: vmerr,
ReturnData: ret,
Expand All @@ -418,17 +417,17 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {

if st.evm.ChainConfig().Scroll.FeeVaultEnabled() {
// The L2 Fee is the same as the fee that is charged in the normal geth
// codepath. Add the L1 fee to the L2 fee for the total fee that is sent
// codepath. Add the L1DataFee to the L2 fee for the total fee that is sent
// to the sequencer.
l2Fee := new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip)
fee := new(big.Int).Add(st.l1Fee, l2Fee)
fee := new(big.Int).Add(st.l1DataFee, l2Fee)
st.state.AddBalance(st.evm.FeeRecipient(), fee)
} else {
st.state.AddBalance(st.evm.FeeRecipient(), new(big.Int).Mul(new(big.Int).SetUint64(st.gasUsed()), effectiveTip))
}

return &ExecutionResult{
L1Fee: st.l1Fee,
L1DataFee: st.l1DataFee,
UsedGas: st.gasUsed(),
Err: vmerr,
ReturnData: ret,
Expand Down
3 changes: 1 addition & 2 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,6 @@ func (pool *TxPool) local() map[common.Address]types.Transactions {
// rules and adheres to some heuristic limits of the local node (price and size).
func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
// No unauthenticated deposits allowed in the transaction pool.
// >>>>>>> scroll/v4.1.0
if tx.IsL1MessageTx() {
return ErrTxTypeNotSupported
}
Expand Down Expand Up @@ -696,7 +695,7 @@ func (pool *TxPool) add(tx *types.Transaction, local bool) (replaced bool, err e

if pool.chainconfig.Scroll.FeeVaultEnabled() {
if err := fees.VerifyFee(pool.signer, tx, pool.currentState); err != nil {
log.Trace("Discarding insufficient l1fee transaction", "hash", hash, "err", err)
log.Trace("Discarding insufficient l1DataFee transaction", "hash", hash, "err", err)
invalidTxMeter.Mark(1)
return false, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/types/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type Header struct {

// BLSData was the field specified for morphism
BLSData BLSData `json:"blsData" rlp:"optional"`
// >>>>>>> scroll/v4.1.0

// WithdrawalsHash was added by EIP-4895 and is ignored in legacy headers.
// Included for Ethereum compatibility in Scroll SDK
WithdrawalsHash *common.Hash `json:"withdrawalsRoot" rlp:"optional"`
Expand Down
39 changes: 19 additions & 20 deletions core/types/gen_header_json.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions core/types/l2trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ type StorageTrace struct {
// while replaying a transaction in debug mode as well as transaction
// execution status, the amount of gas used and the return value
type ExecutionResult struct {
L1Fee uint64 `json:"l1Fee,omitempty"`
Gas uint64 `json:"gas"`
Failed bool `json:"failed"`
ReturnValue string `json:"returnValue"`
L1DataFee *hexutil.Big `json:"l1DataFee,omitempty"`
Gas uint64 `json:"gas"`
Failed bool `json:"failed"`
ReturnValue string `json:"returnValue"`
// Sender's account state (before Tx)
From *AccountWrapper `json:"from,omitempty"`
// Receiver's account state (before Tx)
Expand Down
Loading