-
Notifications
You must be signed in to change notification settings - Fork 17
perf!(ServiceProviderRegistry): Bloom Schema #308
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
Merged
Merged
Changes from 25 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
ba25df6
wip bloom schema
wjmelements 8a503aa
only shift by 8
wjmelements 934f14e
parameterize K
wjmelements 393a5a3
Merge remote-tracking branch 'origin/main' into bloom-schema
wjmelements c08fb7a
test BloomSet16
wjmelements 35dd6c3
Errors.InsufficientCapabilitiesForProduct, and restore prior PDPOffer…
wjmelements 62fd4b2
Merge remote-tracking branch 'origin/main' into bloom-schema
wjmelements 2fb481e
must tag as dev
wjmelements 1fdfd06
bytes[] capability values
wjmelements 11dc0ba
tests build but do not yet pass
wjmelements e317e43
tests pass
wjmelements fc80b4b
mv PDPOffering.sol to test
wjmelements 3d6682d
make update-abi
wjmelements 17bd9ec
update subgraph: ProductUpdated and create product
wjmelements 8061aa6
subgraph: bytes capabilityValues
wjmelements 621f789
remove misleading exists bools
wjmelements f565a89
make ipni fields optional and document ipniPeerId
wjmelements 891e3b6
getAllProductCapabilities, and add capability values to getActiveProv…
wjmelements 7a572f1
make update-abi
wjmelements 5a3224c
else if
wjmelements 2709451
doc getAllProductCapabilities
wjmelements 99d9cf9
ban empty capability value
wjmelements efc9773
forge lint
wjmelements a4d0062
feat(registry): provide more useful accessors (#328)
rvagg 1628fde
Update service_contracts/src/lib/BloomSet.sol
wjmelements 602b0dc
Merge remote-tracking branch 'origin/main' into bloom-schema
wjmelements 3c28451
BigEndian library
wjmelements 94eed74
use big endian encoding in test
wjmelements File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
502 changes: 142 additions & 360 deletions
502
service_contracts/abi/ServiceProviderRegistry.abi.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| pragma solidity ^0.8.30; | ||
|
|
||
| /// @notice Bloom Filter with fixed params: | ||
| /// @notice k = 16 bits per item | ||
| /// @notice m = 256 bits per set | ||
| /// @dev probability of false positives by number of items: (via https://hur.st/bloomfilter/?m=256&k=16) | ||
| /// @dev 7: 0.000000062 | ||
| /// @dev 8: 0.00000033 | ||
| /// @dev 9: 0.000001377 | ||
| /// @dev 10: 0.000004735 | ||
| /// @dev 11: 0.000013933 | ||
| /// @dev 12: 0.000036084 | ||
| /// @dev 13: 0.000084014 | ||
| /// @dev 14: 0.000178789 | ||
| /// @dev 15: 0.000352341 | ||
| library BloomSet16 { | ||
| uint256 private constant K = 16; | ||
| uint256 internal constant EMPTY = 0; | ||
|
|
||
| function compressed(string memory uncompressed) internal pure returns (uint256 item) { | ||
| uint256 hash; | ||
| assembly ("memory-safe") { | ||
| hash := keccak256(add(32, uncompressed), mload(uncompressed)) | ||
| item := 0 | ||
| } | ||
| for (uint256 i = 0; i < K; i++) { | ||
| item |= 1 << (hash & 0xff); | ||
| hash >>= 8; | ||
| } | ||
| } | ||
|
|
||
| /// @notice Checks if set probably contains the items | ||
| /// @return false when the set is definitely missing at least one of the items | ||
| function mayContain(uint256 set, uint256 items) internal pure returns (bool) { | ||
| return set & items == items; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| pragma solidity ^0.8.30; | ||
|
|
||
| import {Test} from "forge-std/Test.sol"; | ||
| import {BloomSet16} from "../src/lib/BloomSet.sol"; | ||
|
|
||
| contract BloomSetTest is Test { | ||
| using BloomSet16 for string; | ||
| using BloomSet16 for uint256; | ||
wjmelements marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function testIdentical() public pure { | ||
| uint256 set = BloomSet16.EMPTY; | ||
| assertTrue(set.mayContain(BloomSet16.EMPTY)); | ||
| string[] memory same = new string[](6); | ||
| for (uint256 i = 0; i < same.length; i++) { | ||
| same[i] = "theVerySame"; | ||
| } | ||
| for (uint256 i = 0; i < same.length; i++) { | ||
| set |= same[i].compressed(); | ||
| } | ||
| assertTrue(set.mayContain(BloomSet16.EMPTY)); | ||
| assertTrue(set.mayContain(set)); | ||
| string memory verySame = "theVerySame"; | ||
| assertEq(set, verySame.compressed()); | ||
| assertTrue(set.mayContain(verySame.compressed())); | ||
| string memory fromCat = string.concat(string.concat("the", "Very"), "Same"); | ||
| assertEq(verySame.compressed(), fromCat.compressed()); | ||
| } | ||
|
|
||
| function testDifferent() public pure { | ||
| uint256 set = BloomSet16.EMPTY; | ||
| string memory one = "1"; | ||
| string memory two = "2"; | ||
| string memory three = "3"; | ||
| set |= one.compressed(); | ||
| assertTrue(set.mayContain(one.compressed())); | ||
| assertFalse(set.mayContain(two.compressed())); | ||
| assertFalse(set.mayContain(three.compressed())); | ||
| set |= two.compressed(); | ||
| assertTrue(set.mayContain(BloomSet16.EMPTY)); | ||
| assertTrue(set.mayContain(one.compressed())); | ||
| assertTrue(set.mayContain(two.compressed())); | ||
| assertFalse(set.mayContain(three.compressed())); | ||
| assertFalse(one.compressed().mayContain(set)); | ||
| assertFalse(two.compressed().mayContain(set)); | ||
| assertFalse(three.compressed().mayContain(set)); | ||
| assertFalse(BloomSet16.EMPTY.mayContain(set)); | ||
| assertFalse(BloomSet16.EMPTY.mayContain(one.compressed())); | ||
| assertFalse(BloomSet16.EMPTY.mayContain(two.compressed())); | ||
| assertFalse(BloomSet16.EMPTY.mayContain(three.compressed())); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.