Utility functions for working with bloom filters #429
Replies: 3 comments 4 replies
-
Currently focused on other things, but down for a contribution! |
Beta Was this translation helpful? Give feedback.
-
Would you be willing to accept a PR with ethereum bloom filter package installed? I am the creator of that package happen to do a PR here so others can use it? |
Beta Was this translation helpful? Give feedback.
-
I'm willing to contribute by adding some bloom filter utilities. I implemented some bloom filter utilities in Ponder (https://github.com/ponder-sh/ponder/blob/main/packages/core/src/sync-realtime/bloom.ts) using viem utilities based off of Alloy. APIconst isLogInBloomFilter: (params: { bloomFilter: Hex, log: Pick<Log, "address" | "topics"> }) => boolean; Could also be nice to have |
Beta Was this translation helpful? Give feedback.
-
Bloom filters are a core Ethereum data structure, so it seems reasonable for viem to offer utility functions for working with them.
Use case
My particular use case is checking if a block contains logs matching a log filter (
addresses
andtopics
) using theblock.logsBloom
field. (I actually can't think of any other use cases, because AFAIK this is the only bloom filter that Ethereum exposes externally).References
Web3.js has a few utility functions for bloom filters. They appear to be a re-export of the ethereum-bloom-filters package, which could be a good starting point.
API
We could start with just a single function to check if a value is present in a bloom filter. This function would validate that the bloom filter is a valid Ethereum logs bloom filter, and return a boolean.
We could also consider supporting a plural version that accepts multiple values, and returns early if any values match. This would be useful for the use case described above.
Beta Was this translation helpful? Give feedback.
All reactions