-
Notifications
You must be signed in to change notification settings - Fork 279
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
[Fix] deletion proof should be collected in log tracing #247
Changes from 2 commits
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ import ( | |
"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/crypto" | ||
"github.com/scroll-tech/go-ethereum/log" | ||
"github.com/scroll-tech/go-ethereum/params" | ||
"github.com/scroll-tech/go-ethereum/rollup/rcfg" | ||
|
@@ -42,6 +43,8 @@ type traceEnv struct { | |
// this lock is used to protect StorageTrace's read and write mutual exclusion. | ||
sMu sync.Mutex | ||
*types.StorageTrace | ||
// used for de-duplication of deletion proofs when handling mutiple txs | ||
deletionProofAgg map[common.Hash][]byte | ||
executionResults []*types.ExecutionResult | ||
} | ||
|
||
|
@@ -119,6 +122,7 @@ func (api *API) createTraceEnv(ctx context.Context, config *TraceConfig, block * | |
Proofs: make(map[string][]hexutil.Bytes), | ||
StorageProofs: make(map[string]map[string][]hexutil.Bytes), | ||
}, | ||
deletionProofAgg: make(map[common.Hash][]byte), | ||
executionResults: make([]*types.ExecutionResult, block.Transactions().Len()), | ||
} | ||
|
||
|
@@ -314,7 +318,7 @@ func (api *API) getTxResult(env *traceEnv, state *state.StateDB, index int, bloc | |
} | ||
env.sMu.Unlock() | ||
|
||
proof, sibling, err := state.GetStorageTrieProof(addr, key) | ||
proof, err := state.GetStorageTrieProof(addr, key) | ||
if err != nil { | ||
log.Error("Storage proof not available", "error", err, "address", addrStr, "key", keyStr) | ||
// but we still mark the proofs map with nil array | ||
|
@@ -325,13 +329,18 @@ func (api *API) getTxResult(env *traceEnv, state *state.StateDB, index int, bloc | |
} | ||
env.sMu.Lock() | ||
m[keyStr] = wrappedProof | ||
if sibling != nil { | ||
env.DeletionProofs = append(env.DeletionProofs, sibling) | ||
} | ||
env.sMu.Unlock() | ||
} | ||
} | ||
|
||
deletionProofs := tracer.DeletionProofs() | ||
for _, bt := range deletionProofs { | ||
key := crypto.Keccak256Hash(bt) | ||
env.sMu.Lock() | ||
noel2004 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
env.deletionProofAgg[key] = bt | ||
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. Do we need the last proof for the same key? Not the first one? 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.
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. Bytes of a node's value? Or its key? If we delete, reinsert, then delete again, this will work? 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 is in fact bytes of 'the whole node', i.e. trie can read these bytes as a valid node and add it to the (temporary) database. Such an entry of node in database is immutable and not affected by insert / updating or deletion. It would just lost any reference from trie when being deleted. So adding any node into database would never break the trie, it just take no use in the worst case. |
||
env.sMu.Unlock() | ||
} | ||
|
||
var l1Fee uint64 | ||
if result.L1Fee != nil { | ||
l1Fee = result.L1Fee.Uint64() | ||
|
@@ -360,6 +369,10 @@ func (api *API) fillBlockTrace(env *traceEnv, block *types.Block) (*types.BlockT | |
txs[i] = types.NewTransactionData(tx, block.NumberU64(), api.backend.ChainConfig()) | ||
} | ||
|
||
for _, bt := range env.deletionProofAgg { | ||
env.DeletionProofs = append(env.DeletionProofs, bt) | ||
} | ||
|
||
blockTrace := &types.BlockTrace{ | ||
ChainID: api.backend.ChainConfig().ChainID.Uint64(), | ||
Version: params.ArchiveVersion(params.CommitHash), | ||
|
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.
What's the expected performance impact of this?
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.
Now we need to do a proof on each deletion (SSTORE a non-zero value to 0). The cost depends while considering the storage trie usually is not very high and deletion is not so common I think the impact should be limited.
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.
Okay, sounds acceptable. We just need to think if this can be triggered maliciously somehow.
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.
You are right. I just recognized that current implement would bring an addition commition on the corresponding storage trie so it may bring significant cost by a series well designed malicious txs in one block.
Lucikly if we should have separated and constrainted the logtrace only work while obtaining block trace, such a attack is mitigated for the cost only raised in any following nodes used for providng block trace.
And I think we can further push the deletion generation process to commiting step, I would start this idea in another PR.
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.
Would trace this problem in #253