Skip to content

Commit

Permalink
Merge scroll tag v3.2.4 into morphism (#9)
Browse files Browse the repository at this point in the history
* feat(trace): add storage proof about l1fee (baseFee, overhead, scalar) and withdraw root into trace (#314)

* add proof for predeployed storages

* reverse inneeded code

* update for mainbranch merging

* add coinbase storage as trace

* comment for clarify

* Update version.go

---------

Co-authored-by: Péter Garamvölgyi <[email protected]>
Co-authored-by: HAOYUatHZ <[email protected]>

* feat: enable eip and update check (#335)

* enable eip and update check

* Update version.go

---------

Co-authored-by: Péter Garamvölgyi <[email protected]>
Co-authored-by: HAOYUatHZ <[email protected]>

* fix(trace): deletion proof missed path terminated by empty node (#330)

* fix deletion proof issue on empty node

* refine for better implement and fix unittest

* Update version.go

---------

Co-authored-by: HAOYUatHZ <[email protected]>

* fix(API): use `hexutil.Big` for `l1Fee` in `GetTransactionReceipt` (#336)

* It's not a bug, but if just translate to hexutil.Big can be better.

* Revert editor's auto change.

* Update version.

* Update version.

---------

Co-authored-by: Ho <[email protected]>
Co-authored-by: Péter Garamvölgyi <[email protected]>
Co-authored-by: HAOYUatHZ <[email protected]>
Co-authored-by: Nazarii Denha <[email protected]>
Co-authored-by: maskpp <[email protected]>
  • Loading branch information
6 people authored May 23, 2023
1 parent 69cf63f commit fedb314
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 6 deletions.
5 changes: 5 additions & 0 deletions core/tx_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package core

import (
"errors"
"fmt"
"math"
"math/big"
"sort"
Expand Down Expand Up @@ -619,6 +620,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
if uint64(tx.Size()) > txMaxSize {
return ErrOversizedData
}
// Check whether the init code size has been exceeded.
if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
return fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
}
// Transactions can't be negative. This may never happen using RLP decoded
// transactions but may occur if you create a transaction using the RPC.
if tx.Value().Sign() < 0 {
Expand Down
5 changes: 4 additions & 1 deletion core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ var (
// JumpTable contains the EVM opcodes supported at a given fork.
type JumpTable [256]*operation

// newShanghaiInstructionSet returns the frontier, homestead, byzantium,
// contantinople, istanbul, petersburg, berlin, london and shanghai instructions.
func newShanghaiInstructionSet() JumpTable {
instructionSet := newLondonInstructionSet()
enable3860(&instructionSet)
enable3855(&instructionSet) // PUSH0 instruction https://eips.ethereum.org/EIPS/eip-3855
enable3860(&instructionSet) // Limit and meter initcode https://eips.ethereum.org/EIPS/eip-3860
return instructionSet
}

Expand Down
37 changes: 37 additions & 0 deletions eth/tracers/api_blocktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ func (api *API) getTxResult(env *traceEnv, state *state.StateDB, index int, bloc

// merge required proof data
proofAccounts := tracer.UpdatedAccounts()
proofAccounts[vmenv.FeeRecipient()] = struct{}{}
proofAccounts[rcfg.L1GasPriceOracleAddress] = struct{}{}
for addr := range proofAccounts {
addrStr := addr.String()

Expand All @@ -314,6 +316,12 @@ func (api *API) getTxResult(env *traceEnv, state *state.StateDB, index int, bloc
}

proofStorages := tracer.UpdatedStorages()
proofStorages[rcfg.L1GasPriceOracleAddress] = vm.Storage(
map[common.Hash]common.Hash{
rcfg.L1BaseFeeSlot: {}, // notice we do not need the right value here
rcfg.OverheadSlot: {},
rcfg.ScalarSlot: {},
})
for addr, keys := range proofStorages {
env.sMu.Lock()
trie, err := state.GetStorageTrieForProof(addr)
Expand Down Expand Up @@ -404,6 +412,35 @@ func (api *API) fillBlockTrace(env *traceEnv, block *types.Block) (*types.BlockT
txs[i] = types.NewTransactionData(tx, block.NumberU64(), api.backend.ChainConfig())
}

if _, existed := env.Proofs[rcfg.L2MessageQueueAddress.String()]; !existed {
if proof, err := statedb.GetProof(rcfg.L2MessageQueueAddress); err != nil {
log.Error("Proof for L2MessageQueueAddress not available", "error", err)
} else {
wrappedProof := make([]hexutil.Bytes, len(proof))
for i, bt := range proof {
wrappedProof[i] = bt
}
env.Proofs[rcfg.L2MessageQueueAddress.String()] = wrappedProof
}
}

if _, existed := env.StorageProofs[rcfg.L2MessageQueueAddress.String()]; !existed {
env.StorageProofs[rcfg.L2MessageQueueAddress.String()] = make(map[string][]hexutil.Bytes)
}
if _, existed := env.StorageProofs[rcfg.L2MessageQueueAddress.String()][rcfg.WithdrawTrieRootSlot.String()]; !existed {
if trie, err := statedb.GetStorageTrieForProof(rcfg.L2MessageQueueAddress); err != nil {
log.Error("Storage proof for WithdrawTrieRootSlot not available", "error", err)
} else if proof, _ := statedb.GetSecureTrieProof(trie, rcfg.WithdrawTrieRootSlot); err != nil {
log.Error("Get storage proof for WithdrawTrieRootSlot failed", "error", err)
} else {
wrappedProof := make([]hexutil.Bytes, len(proof))
for i, bt := range proof {
wrappedProof[i] = bt
}
env.StorageProofs[rcfg.L2MessageQueueAddress.String()][rcfg.WithdrawTrieRootSlot.String()] = wrappedProof
}
}

blockTrace := &types.BlockTrace{
ChainID: api.backend.ChainConfig().ChainID.Uint64(),
Version: params.ArchiveVersion(params.CommitHash),
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ func (s *PublicTransactionPoolAPI) GetTransactionReceipt(ctx context.Context, ha
"logs": receipt.Logs,
"logsBloom": receipt.Bloom,
"type": hexutil.Uint(tx.Type()),
"l1Fee": hexutil.Uint64(receipt.L1Fee.Uint64()),
"l1Fee": (*hexutil.Big)(receipt.L1Fee),
}
// Assign the effective gas price paid
if !s.b.ChainConfig().IsLondon(bigblock) {
Expand Down
2 changes: 1 addition & 1 deletion params/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
const (
VersionMajor = 3 // Major version component of the current release
VersionMinor = 2 // Minor version component of the current release
VersionPatch = 0 // Patch version component of the current release
VersionPatch = 4 // Patch version component of the current release
VersionMeta = "alpha" // Version metadata to append to the version string
)

Expand Down
5 changes: 3 additions & 2 deletions trie/zk_trie_proof_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,12 @@ func TestProofWithDeletion(t *testing.T) {
// notice the sibling of key `k*32`` is just the leaf of key `m*32`
assert.Equal(t, siblings[0][l-33:l-1], nd)

// no effect
// Marking a key that is currently not hit (but terminated by an empty node)
// also causes it to be added to the deletion proof
proofTracer.MarkDeletion(s_key2.Bytes())
siblings, err = proofTracer.GetDeletionProofs()
assert.NoError(t, err)
assert.Equal(t, 1, len(siblings))
assert.Equal(t, 2, len(siblings))

key3 := bytes.Repeat([]byte("x"), 32)
err = mt.UpdateWord(
Expand Down
13 changes: 12 additions & 1 deletion trie/zktrie_deletionproof.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type ProofTracer struct {
*ZkTrie
deletionTracer map[zkt.Hash]struct{}
rawPaths map[string][]*zktrie.Node
emptyTermPaths map[string][]*zktrie.Node
}

// NewProofTracer create a proof tracer object
Expand All @@ -37,6 +38,7 @@ func (t *ZkTrie) NewProofTracer() *ProofTracer {
// always consider 0 is "deleted"
deletionTracer: map[zkt.Hash]struct{}{zkt.HashZero: {}},
rawPaths: make(map[string][]*zktrie.Node),
emptyTermPaths: make(map[string][]*zktrie.Node),
}
}

Expand Down Expand Up @@ -112,9 +114,13 @@ func (t *ProofTracer) GetDeletionProofs() ([][]byte, error) {

// MarkDeletion mark a key has been involved into deletion
func (t *ProofTracer) MarkDeletion(key []byte) {
if path, existed := t.rawPaths[string(key)]; existed {
if path, existed := t.emptyTermPaths[string(key)]; existed {
// copy empty node terminated path for final scanning
t.rawPaths[string(key)] = path
} else if path, existed = t.rawPaths[string(key)]; existed {
// sanity check
leafNode := path[len(path)-1]

if leafNode.Type != zktrie.NodeTypeLeaf {
panic("all path recorded in proofTrace should be ended with leafNode")
}
Expand Down Expand Up @@ -143,6 +149,11 @@ func (t *ProofTracer) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWr
}
} else if n.Type == zktrie.NodeTypeParent {
mptPath = append(mptPath, n)
} else if n.Type == zktrie.NodeTypeEmpty {
// empty node is considered as "unhit" but it should be also being added
// into a temporary slot for possibly being marked as deletion later
mptPath = append(mptPath, n)
t.emptyTermPaths[string(key)] = mptPath
}

return proofDb.Put(nodeHash[:], n.Value())
Expand Down

0 comments on commit fedb314

Please sign in to comment.