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) Zz/feat/flattenproof plus txbytxtraces #1025

Draft
wants to merge 26 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0a0e396
WIP: flatten storageproof
noel2004 Jul 30, 2024
330ad97
WIP: for testing
noel2004 Jul 30, 2024
623cbe2
Merge remote-tracking branch 'origin/develop' into develop
noel2004 Jul 30, 2024
06fdc8c
fix: init map
noel2004 Jul 30, 2024
11a21da
fix lock issue
noel2004 Jul 30, 2024
2238551
add deletion proof
noel2004 Jul 30, 2024
d56e002
Merge remote-tracking branch 'scroll/develop' into feat/flattenproof
noel2004 Aug 3, 2024
7abeb46
fix endian represent of key
noel2004 Aug 3, 2024
84b00d2
add flatten proof for coinbase
noel2004 Aug 4, 2024
49151d4
WIP: preimage for key
noel2004 Aug 7, 2024
4e7a02f
Merge remote-tracking branch 'origin/develop' into feat/flattenproof
noel2004 Aug 7, 2024
8c2611c
key hash records
noel2004 Aug 7, 2024
a290561
Merge remote-tracking branch 'origin/develop' into feat/flattenproof
noel2004 Aug 13, 2024
3a805b4
filter for l2trace
noel2004 Aug 13, 2024
11b45dc
Merge remote-tracking branch 'origin/develop' into feat/flattenproof
noel2004 Aug 21, 2024
2a2b2b8
add union mode
noel2004 Aug 21, 2024
164adae
fix typo
noel2004 Aug 21, 2024
da019ee
fix go imports
noel2004 Aug 21, 2024
a85536a
Merge remote-tracking branch 'origin/develop' into feat/flattenproof
noel2004 Aug 22, 2024
13e46cf
set default format to legacy
noel2004 Aug 22, 2024
7968829
++
omerfirmak Aug 22, 2024
5ec1a25
Merge remote-tracking branch 'origin/omerfirmak/tx-by-tx-tracer' into…
lispc Aug 27, 2024
78e6f64
Merge remote-tracking branch 'origin/develop' into zz/feat/flattenpro…
lispc Sep 5, 2024
903a85a
Merge remote-tracking branch 'origin/develop' into zz/feat/flattenpro…
lispc Sep 6, 2024
e565e14
induce partial trace mode
noel2004 Sep 7, 2024
9ce5c5a
disable trace filter
noel2004 Sep 7, 2024
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
16 changes: 15 additions & 1 deletion eth/tracers/api_blocktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ type TraceBlock interface {
GetTxBlockTraceOnTopOfBlock(ctx context.Context, tx *types.Transaction, blockNrOrHash rpc.BlockNumberOrHash, config *TraceConfig) (*types.BlockTrace, error)
}

type TracerEnv interface {
ResetForPartialTrace(*types.Block) error
GetBlockTrace(*types.Block) (*types.BlockTrace, error)
}

type scrollTracerWrapper interface {
CreateTraceEnvAndGetBlockTrace(*params.ChainConfig, core.ChainContext, consensus.Engine, ethdb.Database, *state.StateDB, *types.Block, *types.Block, bool) (*types.BlockTrace, error)
CreateTraceEnv(*params.ChainConfig, core.ChainContext, consensus.Engine, ethdb.Database, *state.StateDB, *types.Block, *types.Block, bool) (TracerEnv, error)
}

// GetBlockTraceByNumberOrHash replays the block and returns the structured BlockTrace by hash or number.
Expand Down Expand Up @@ -132,12 +138,20 @@ func (api *API) GetTxByTxBlockTrace(ctx context.Context, blockNrOrHash rpc.Block

chaindb := api.backend.ChainDb()
traces := []*types.BlockTrace{}
traceEnv, err := api.scrollTracerWrapper.CreateTraceEnv(api.backend.ChainConfig(), api.chainContext(ctx), api.backend.Engine(), chaindb, statedb, parent, block, true)
if err != nil {
return nil, err
}
for _, tx := range block.Transactions() {
singleTxBlock := types.NewBlockWithHeader(block.Header()).WithBody([]*types.Transaction{tx}, nil)
trace, err := api.scrollTracerWrapper.CreateTraceEnvAndGetBlockTrace(api.backend.ChainConfig(), api.chainContext(ctx), api.backend.Engine(), chaindb, statedb, parent, singleTxBlock, true)
if err := traceEnv.ResetForPartialTrace(singleTxBlock); err != nil {
return nil, err
}
trace, err := traceEnv.GetBlockTrace(singleTxBlock)
if err != nil {
return nil, err
}
trace.StorageTrace.ApplyFilter(false)
traces = append(traces, trace)
}
return traces, nil
Expand Down
40 changes: 40 additions & 0 deletions rollup/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func NewTracerWrapper() *TracerWrapper {
return &TracerWrapper{}
}

func (tw *TracerWrapper) CreateTraceEnv(chainConfig *params.ChainConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, parent *types.Block, block *types.Block, commitAfterApply bool) (tracers.TracerEnv, error) {
traceEnv, err := CreateTraceEnv(chainConfig, chainContext, engine, chaindb, statedb, parent, block, commitAfterApply)
return traceEnv, err
}

// CreateTraceEnvAndGetBlockTrace wraps the whole block tracing logic for a block
func (tw *TracerWrapper) CreateTraceEnvAndGetBlockTrace(chainConfig *params.ChainConfig, chainContext core.ChainContext, engine consensus.Engine, chaindb ethdb.Database, statedb *state.StateDB, parent *types.Block, block *types.Block, commitAfterApply bool) (*types.BlockTrace, error) {
traceEnv, err := CreateTraceEnv(chainConfig, chainContext, engine, chaindb, statedb, parent, block, commitAfterApply)
Expand Down Expand Up @@ -192,6 +197,41 @@ func CreateTraceEnv(chainConfig *params.ChainConfig, chainContext core.ChainCont
return env, nil
}

func (env *TraceEnv) ResetForPartialTrace(partialBlk *types.Block) error {

if env.StorageTrace == nil {
return fmt.Errorf("not init")
}

// TODO: can we chained the RootBefore / After?
oldStorage := env.StorageTrace

// only reset which can be reset
env.signer = types.MakeSigner(env.chainConfig, partialBlk.Number())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why reset env.signer?

env.StorageTrace = &types.StorageTrace{
RootBefore: oldStorage.RootBefore,
RootAfter: partialBlk.Root(),
Copy link
Author

@lispc lispc Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this line O(1): yes. read only.

Proofs: make(map[string][]hexutil.Bytes),
StorageProofs: make(map[string]map[string][]hexutil.Bytes),
FlattenProofs: make(map[common.Hash]hexutil.Bytes),
AddressHashes: make(map[common.Address]common.Hash),
StoreKeyHashes: make(map[common.Hash]common.Hash),
}
env.Codes = make(map[common.Hash]vm.CodeInfo)
env.ExecutionResults = make([]*types.ExecutionResult, partialBlk.Transactions().Len())
env.TxStorageTraces = make([]*types.StorageTrace, partialBlk.Transactions().Len())

// still need to restore coinbase's proof ....
proof, addrHash, err := env.state.GetFullProof(env.coinbase)
if err == nil {
env.AddressHashes[env.coinbase] = addrHash
env.fillFlattenStorageProof(nil, proof)
env.Proofs[env.coinbase.String()] = types.WrapProof(proof.GetData())
}

return nil
}

func (env *TraceEnv) GetBlockTrace(block *types.Block) (*types.BlockTrace, error) {
// Execute all the transaction contained within the block concurrently
var (
Expand Down