@@ -18,11 +18,12 @@ import (
1818)
1919
2020const (
21- flagBlockField = "field"
22- flagBlockFull = "full"
23- flagBlockRpcUrl = "rpc-url"
24- flagBlockJson = "json"
25- flagBlockCheckLogs = "check-logs-bloom"
21+ flagBlockField = "field"
22+ flagBlockFull = "full"
23+ flagBlockRpcUrl = "rpc-url"
24+ flagBlockJson = "json"
25+ flagBlockCheckLogs = "check-logs-bloom"
26+ flagBlockIgnoreZeroGasLogs = "ignore-zero-gas-logs"
2627)
2728
2829func init () {
@@ -48,6 +49,7 @@ func NewBlockCmd() *cobra.Command {
4849 cmd .Flags ().StringP (flagBlockRpcUrl , "r" , "" , "The RPC endpoint to the blockchain node to interact with" )
4950 cmd .Flags ().BoolP (flagBlockJson , "j" , false , "Print the block as JSON" )
5051 cmd .Flags ().Bool (flagBlockCheckLogs , false , "Check logs bloom against the block header reported value" )
52+ cmd .Flags ().Bool (flagBlockIgnoreZeroGasLogs , false , "Ignore logs from transactions with gas price 0 when checking bloom (HyperEVM system txs)" )
5153
5254 return cmd
5355}
@@ -74,6 +76,10 @@ func (c *block) Run(cmd *cobra.Command, args []string) error {
7476 if err != nil {
7577 return err
7678 }
79+ fIgnoreZeroGasLogs , err := cmd .Flags ().GetBool (flagBlockIgnoreZeroGasLogs )
80+ if err != nil {
81+ return err
82+ }
7783
7884 if _ , err = url .ParseRequestURI (fRpc ); err != nil {
7985 return errors .New ("error: please provide a valid rpc url (e.g. https://nodes.sequence.app/mainnet)" )
@@ -115,7 +121,7 @@ func (c *block) Run(cmd *cobra.Command, args []string) error {
115121 }
116122
117123 if fBlockCheckLogs {
118- CheckLogs (block , provider )
124+ CheckLogs (block , provider , fIgnoreZeroGasLogs )
119125 }
120126
121127 fmt .Fprintln (cmd .OutOrStdout (), obj )
@@ -268,7 +274,7 @@ func (b *Block) String() string {
268274}
269275
270276// CheckLogs verifies that the logs bloom and logs hash in the block header match the actual logs
271- func CheckLogs (block * types.Block , provider * ethrpc.Provider ) {
277+ func CheckLogs (block * types.Block , provider * ethrpc.Provider , ignoreZeroGasLogs bool ) {
272278 h , err := provider .HeaderByNumber (context .Background (), block .Number ())
273279
274280 if err != nil {
@@ -284,23 +290,38 @@ func CheckLogs(block *types.Block, provider *ethrpc.Provider) {
284290 fmt .Println ("Error getting logs:" , err )
285291 }
286292
293+ filteredLogs := logs
294+ if ignoreZeroGasLogs {
295+ filteredLogs = zeroGasLogsFilter (logs , h , block )
296+ }
297+
287298 fmt .Printf ("Block: %d\n " , h .Number .Uint64 ())
288- fmt .Printf ("Logs Count: %d\n " , len (logs ))
289- fmt .Printf ("Match: %v\n " , ethutil .ValidateLogsWithBlockHeader (logs , h ))
299+ fmt .Printf ("Logs Count: %d\n " , len (filteredLogs ))
300+ fmt .Printf ("Match: %v\n " , ethutil .ValidateLogsWithBlockHeader (filteredLogs , h ))
290301 fmt .Println ()
291- fmt .Printf ("Calculated Log Bloom: 0x%x\n " , logsToBloom ( logs ).Bytes ())
302+ fmt .Printf ("Calculated Log Bloom: 0x%x\n " , ethutil . ConvertLogsToBloom ( filteredLogs ).Bytes ())
292303 fmt .Println ()
293304 fmt .Printf ("Header Log Bloom: 0x%x\n " , h .Bloom .Bytes ())
294305 fmt .Println ()
295306}
296307
297- func logsToBloom (logs []types.Log ) types.Bloom {
298- var logBloom types.Bloom
299- for _ , log := range logs {
300- logBloom .Add (log .Address .Bytes ())
301- for _ , b := range log .Topics {
302- logBloom .Add (b [:])
308+ // zeroGasLogsFilter removes logs from transactions whose gas price is zero
309+ // (HyperEVM system transactions).
310+ var _ ethutil.LogsFilterFunc = zeroGasLogsFilter
311+
312+ func zeroGasLogsFilter (ls []types.Log , _ * types.Header , block * types.Block ) []types.Log {
313+ gasPriceByTx := make (map [common.Hash ]* big.Int , len (block .Transactions ()))
314+ for _ , tx := range block .Transactions () {
315+ gasPriceByTx [tx .Hash ()] = tx .GasPrice ()
316+ }
317+
318+ out := make ([]types.Log , 0 , len (ls ))
319+ for _ , l := range ls {
320+ if gp , ok := gasPriceByTx [l .TxHash ]; ok && gp .Sign () == 0 {
321+ // HyperEVM system tx (gas price = 0) — ignore for bloom validation.
322+ continue
303323 }
324+ out = append (out , l )
304325 }
305- return logBloom
326+ return out
306327}
0 commit comments