Skip to content

Commit

Permalink
fix: do not hash log values; decode as cbor byte arrays.
Browse files Browse the repository at this point in the history
  • Loading branch information
raulk committed Nov 16, 2022
1 parent b904517 commit 23007b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,10 @@ type EthLog struct {
Address EthAddress `json:"address"`

// Data is the value of the event log, excluding topics
Data EthHash `json:"data"`
Data EthBytes `json:"data"`

// List of topics associated with the event log.
Topics []EthHash `json:"topics"`
Topics []EthBytes `json:"topics"`

// Following fields are derived from the transaction containing the log

Expand Down
27 changes: 21 additions & 6 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,11 @@ func ethFilterResultFromEvents(evs []*filter.CollectedEvent) (*api.EthFilterResu
var err error

for _, entry := range ev.Entries {
hash := api.EthHashData(entry.Value)
value := api.EthBytes(decodeLogBytes(entry.Value))
if entry.Key == api.EthTopic1 || entry.Key == api.EthTopic2 || entry.Key == api.EthTopic3 || entry.Key == api.EthTopic4 {
log.Topics = append(log.Topics, hash)
log.Topics = append(log.Topics, value)
} else {
log.Data = hash
log.Data = value
}
}

Expand Down Expand Up @@ -1499,11 +1499,11 @@ func newEthTxReceipt(ctx context.Context, tx api.EthTx, lookup *api.MsgLookup, r
}

for _, entry := range evt.Entries {
hash := api.EthHashData(entry.Value)
value := api.EthBytes(decodeLogBytes(entry.Value))
if entry.Key == api.EthTopic1 || entry.Key == api.EthTopic2 || entry.Key == api.EthTopic3 || entry.Key == api.EthTopic4 {
l.Topics = append(l.Topics, hash)
l.Topics = append(l.Topics, value)
} else {
l.Data = hash
l.Data = value
}
}

Expand Down Expand Up @@ -1531,3 +1531,18 @@ func newEthTxReceipt(ctx context.Context, tx api.EthTx, lookup *api.MsgLookup, r

return receipt, nil
}

// decodeLogBytes decodes a CBOR-serialized array into its original form.
//
// This function swallows errors and returns the original array if it failed
// to decode.
func decodeLogBytes(orig []byte) []byte {
if orig == nil {
return orig
}
decoded, err := cbg.ReadByteArray(bytes.NewReader(orig), uint64(len(orig)))
if err != nil {
return orig
}
return decoded
}

0 comments on commit 23007b0

Please sign in to comment.