Skip to content
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

feat: Switch from Namefilter to Name Accumulators #247

Merged
merged 67 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
b891286
feat: Add wnfs-nameaccumulator crate
matheus23 Mar 28, 2023
b526c09
WIP: refactor
matheus23 Mar 28, 2023
f614077
WIP
matheus23 Mar 30, 2023
fda9507
Type checker
matheus23 May 2, 2023
29a0218
Checkpoint: No failing unit tests
matheus23 May 2, 2023
bd1e357
Remove wnfs-namefilter
matheus23 May 2, 2023
639f68f
feat: Benchmarks for name accumulators
matheus23 May 3, 2023
1a0a078
chore: Use published skip ratchet version
matheus23 May 3, 2023
a142335
refactor out Name abstraction
matheus23 May 16, 2023
b64ae42
cargo clippy --fix
matheus23 May 16, 2023
eb4c6fe
Run proptests less often
matheus23 May 16, 2023
ca9d6d6
refactor: use shorter AccumulatorSetup names
matheus23 May 16, 2023
0a82e73
Make header's name based on mountpoint
matheus23 May 19, 2023
00096fd
Mount files and directories to explicit paths
matheus23 May 22, 2023
a196f89
refactor: Some forest function renames & moving code around
matheus23 Jun 12, 2023
4469ce0
Implement proof generation
matheus23 Jun 14, 2023
75f24aa
Attach proof info to PrivateForest entries
matheus23 Jun 15, 2023
7c0bb1a
One proof for each CID in forest
matheus23 Jun 16, 2023
9049866
Implement batch proving library functions
matheus23 Jun 19, 2023
44320db
Revert PrivateForest back to storing just sets of CIDs
matheus23 Jun 19, 2023
4bc4d45
Refactor out trait PrivateForest
matheus23 Jun 19, 2023
a9a58ea
Refactor PrivateForest trait to be Rc-independent
matheus23 Jun 19, 2023
de0829a
Move forest-related files into own directory
matheus23 Jun 20, 2023
19b67d9
Don't re-expose, implement PrivateForest with and without Rc for Hamt…
matheus23 Jun 20, 2023
d3f46bf
Implement get_mut in hamt node
matheus23 Jun 20, 2023
059cd14
Implement private forest label proof aggregation
matheus23 Jun 20, 2023
382dd95
Fix mounting
matheus23 Jun 21, 2023
2965aa4
Write an example for forest proofs
matheus23 Jun 21, 2023
14e0181
Merge branch 'main' into matheus23/name-accumulators
matheus23 Jun 21, 2023
85fe130
Fix some clippy warnings
matheus23 Jun 21, 2023
a425979
Fix doctests
matheus23 Jun 22, 2023
e4fc088
Move more structs into serializable.rs
matheus23 Jun 22, 2023
5d70a1d
Fix all clippy warnings.
matheus23 Jun 22, 2023
fc4f111
Use once_cell crate instead of std::cell for backwards compat
matheus23 Jun 22, 2023
51b5c69
Make clippy happy?
matheus23 Jun 22, 2023
93e7a5c
Make clippy nightly happy!
matheus23 Jun 22, 2023
a0c7f42
Possibly fix wasm bindings
matheus23 Jun 23, 2023
4018894
Uncomment two tests
matheus23 Jun 26, 2023
56b5d49
Also prove removals in proving forest
matheus23 Jun 26, 2023
b5741f1
Go through some TODOs
matheus23 Jun 26, 2023
da2f673
Zeroize toxic waste
matheus23 Jun 26, 2023
01dddc1
Consistently use `CryptoRngCore` instead of `RngCore`
matheus23 Jun 26, 2023
e9e6fd7
Write docstrings
matheus23 Jun 26, 2023
dff10ac
Document more & remove unused
matheus23 Jun 27, 2023
3c66316
Organize name accumulator tests
matheus23 Jun 27, 2023
ad378c6
Merge branch 'main' into matheus23/name-accumulators
matheus23 Jun 27, 2023
c236b07
Move proofs example to example dir
matheus23 Jun 27, 2023
2204289
Fix wasm types
matheus23 Jun 27, 2023
75eaa5f
Tests in proofs.rs
matheus23 Jun 27, 2023
f664e99
Small cleanup and fixes
matheus23 Jun 28, 2023
2fefe35
Switch to big endian for BigUints in general (RSA moduli are usually …
matheus23 Jun 28, 2023
60c7392
Update readme, remove `Namefilter` mentions
matheus23 Jun 28, 2023
aa012a8
Canonicalize l hash derivation
matheus23 Jun 28, 2023
4b8c38d
Correctly encode big integers with padding
matheus23 Jun 29, 2023
3e9a155
Add previously failing test case
matheus23 Jun 29, 2023
76627f1
Better domain separation strings
matheus23 Jun 29, 2023
122fa2a
Derive the name segment directly from the key
matheus23 Jun 30, 2023
8847177
Remove redundant `as_ref()` + format
matheus23 Jul 6, 2023
1858600
Remove `with_seed` and related APIs
matheus23 Jul 6, 2023
4249362
Use `HamtForest::load` and `store` everywhere
matheus23 Jul 7, 2023
9605bcb
Remove generic from `HamtForest`
matheus23 Jul 7, 2023
0b5e9a5
Update wnfs/src/private/keys/privateref.rs
matheus23 Jul 7, 2023
2e4da26
Update wnfs/examples/write_proofs.rs
matheus23 Jul 7, 2023
964b02a
Rename "saturated" into "revisioned"
matheus23 Jul 7, 2023
17023a7
Run webpack as a separate CI step
matheus23 Jul 7, 2023
7bbfc1d
Merge branch 'main' into matheus23/name-accumulators
matheus23 Jul 7, 2023
80da16b
Adjust new js test from main
matheus23 Jul 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,8 @@ jobs:
- name: Install Playwright
run: npx playwright install --with-deps

- name: Run Webpack
run: cd tests/server && npx webpack

- name: Run Playwright Tests
run: yarn playwright test
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"wnfs-bench": "0.1.22",
"wnfs-common": "0.1.22",
"wnfs-hamt": "0.1.22",
"wnfs-namefilter": "0.1.22",
"wnfs-nameaccumulator": "0.1.22",
"wnfs-wasm": "0.1.22"
}
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ members = [
"wnfs-bench",
"wnfs-common",
"wnfs-hamt",
"wnfs-namefilter",
"wnfs-nameaccumulator",
"wnfs-wasm",
]

Expand Down
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ This library is designed with WebAssembly in mind. You can follow instructions o
- [wnfs](https://github.com/wnfs-wg/rs-wnfs/tree/main/wnfs)
- [wnfs-common](https://github.com/wnfs-wg/rs-wnfs/tree/main/wnfs-common)
- [wnfs-hamt](https://github.com/wnfs-wg/rs-wnfs/tree/main/wnfs-hamt)
- [wnfs-namefilter](https://github.com/wnfs-wg/rs-wnfs/tree/main/wnfs-namefilter)
- [wnfs-nameaccumulator](https://github.com/wnfs-wg/rs-wnfs/tree/main/wnfs-nameaccumulator)
- [wnfs-wasm](https://github.com/wnfs-wg/rs-wnfs/tree/main/wnfs-wasm)

## Building the Project
Expand Down Expand Up @@ -216,9 +216,11 @@ use anyhow::Result;
use chrono::Utc;
use rand::thread_rng;
use std::rc::Rc;
use wnfs::private::{PrivateDirectory, PrivateForest};
use wnfs::private::{
PrivateDirectory,
forest::{hamt::HamtForest, traits::PrivateForest},
};
use wnfs_common::MemoryBlockStore;
use wnfs_namefilter::Namefilter;

#[async_std::main]
async fn main() -> Result<()> {
Expand All @@ -229,11 +231,11 @@ async fn main() -> Result<()> {
let rng = &mut thread_rng();

// Create a private forest.
let forest = &mut Rc::new(PrivateForest::new());
let forest = &mut Rc::new(HamtForest::new_trusted(rng));

// Create a new private directory.
let dir = &mut Rc::new(PrivateDirectory::new(
Namefilter::default(),
&forest.empty_name(),
Utc::now(),
rng,
));
Expand Down Expand Up @@ -270,11 +272,11 @@ async fn main() -> Result<()> {
}
```

This example introduces a few new concepts. The first is the `PrivateForest` which is a HAMT that can contain multiple file trees.
This example introduces a few new concepts. The first is the `HamtForest` which is a HAMT that can contain multiple file trees and implements the `PrivateForest` interface needed for persisting private file systems.

The second is the `Namefilter` (a fixed-size bloomfilter) that lets us identify nodes in the filesystem, and are suitable for offspring checks. Namefilters currently have limitation on how deep the file tree can go but that is going to change in the near future.
The second is the `Name` (returned from `forest.empty_name()`) and `NameAccumulator` that lets us identify nodes in the filesystem, and are suitable for offspring proving.

Finally, we have the random number generator, `rng`, that the library uses for ridding predictability and avoiding collisions in the `PrivateForest`.
Finally, we have the random number generator, `rng`, that the library uses for generating new keys and other random values needed for the protocol.

Check the [`wnfs/examples/`][wnfs-examples] folder for more examples.

Expand Down
5 changes: 5 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
cognitive-complexity-threshold = 10
ignore-interior-mutability = [
"bytes::Bytes",
"wnfs::private::encrypted::Encrypted",
"wnfs_nameaccumulator::NameAccumulator",
]
2 changes: 1 addition & 1 deletion release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"wnfs-wasm": {},
"wnfs-common": {},
"wnfs-hamt": {},
"wnfs-namefilter": {}
"wnfs-nameaccumulator": {}
}
}
32 changes: 16 additions & 16 deletions scripts/rs-wnfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ help() {
echo " rs-wnfs [COMMAND] [...args]"
echo ""
echo "COMMAND:"
echo " * build [--fs|--wasm|--common|--hamt|--filter] - build projects"
echo " * test [--fs|--wasm|--common|--hamt|--filter] - run tests"
echo " * build [--fs|--wasm|--common|--hamt|--accumulator] - build projects"
echo " * test [--fs|--wasm|--common|--hamt|--accumulator] - run tests"
echo " * bench - run wnfs benchmarks"
echo " * setup - install rs-wnfs script"
echo " * help - print this help message"
Expand All @@ -90,7 +90,7 @@ help() {
# Builds the project.
#
# USAGE:
# rs-wnfs build [--fs|--wasm|--common|--hamt|--filter]
# rs-wnfs build [--fs|--wasm|--common|--hamt|--accumulator]
#
build() {
if check_flag --fs; then
Expand All @@ -101,12 +101,12 @@ build() {
build_common
elif check_flag --hamt; then
build_hamt
elif check_flag --filter; then
build_filter
elif check_flag --accumulator; then
build_accumulator
else
build_common
build_hamt
build_filter
build_accumulator
build_fs
build_wasm
fi
Expand All @@ -127,9 +127,9 @@ build_hamt() {
cargo build -p wnfs-hamt --release
}

build_filter() {
display_header "💿 | BUILDING WNFS-NAMEFILTER PROJECT | 💿"
cargo build -p wnfs-namefilter --release
build_accumulator() {
display_header "💿 | BUILDING WNFS-NAMEACCUMULATOR PROJECT | 💿"
cargo build -p wnfs-nameaccumulator --release
}

build_wasm() {
Expand All @@ -147,7 +147,7 @@ build_wasm() {
# Runs tests.
#
# USAGE:
# rs-wnfs test [--fs|--wasm|--common|--hamt|--filter]
# rs-wnfs test [--fs|--wasm|--common|--hamt|--accumulator]
#
test() {
if check_flag --fs; then
Expand All @@ -158,12 +158,12 @@ test() {
test_common
elif check_flag --hamt; then
test_hamt
elif check_flag --filter; then
test_filter
elif check_flag --accumulator; then
test_accumulator
else
test_common
test_hamt
test_filter
test_accumulator
test_fs
test_wasm
fi
Expand All @@ -184,9 +184,9 @@ test_hamt() {
cargo test -p wnfs-hamt
}

test_filter() {
display_header "🧪 | RUNNING WNFS-NAMEFILTER TESTS | 🧪"
cargo test -p wnfs-namefilter
test_accumulator() {
display_header "🧪 | RUNNING WNFS-NAMEACCUMULATOR TESTS | 🧪"
cargo test -p wnfs-nameaccumulator
}

test_wasm() {
Expand Down
8 changes: 5 additions & 3 deletions wnfs-bench/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@ async-std = { version = "1.11", features = ["attributes"] }
chrono = { version = "0.4", default-features = false, features = ["clock", "std"] }
criterion = { version = "0.4", features = ["async_std"] }
proptest = "1.1"
rand = "0.8"
sha3 = "0.10"
wnfs = { path = "../wnfs" }
wnfs-common = { path = "../wnfs-common", features = ["test_utils"] }
wnfs-hamt = { path = "../wnfs-hamt", features = ["test_utils"] }
wnfs-namefilter = { path = "../wnfs-namefilter" }
wnfs-nameaccumulator = { path = "../wnfs-nameaccumulator" }

[[bench]]
name = "hamt"
harness = false
path = "hamt.rs"

[[bench]]
name = "namefilter"
name = "nameaccumulator"
harness = false
path = "namefilter.rs"
path = "nameaccumulator.rs"
58 changes: 29 additions & 29 deletions wnfs-bench/hamt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use wnfs_hamt::{

fn node_set(c: &mut Criterion) {
let mut runner = TestRunner::deterministic();
let mut store = MemoryBlockStore::default();
let store = MemoryBlockStore::default();
let operations = operations(any::<[u8; 32]>(), any::<u64>(), 1_000_000).sample(&mut runner);
let node =
&async_std::task::block_on(async { node_from_operations(&operations, &mut store).await })
&async_std::task::block_on(async { node_from_operations(&operations, &store).await })
.expect("Couldn't setup HAMT node from operations");

let store = Arc::new(store);
Expand All @@ -30,12 +30,11 @@ fn node_set(c: &mut Criterion) {
(store, kv)
},
|(store, (key, value))| async move {
black_box(
Rc::clone(node)
.set(key, value, store.as_ref())
.await
.unwrap(),
);
Rc::clone(node)
.set(key, value, store.as_ref())
.await
.unwrap();
black_box(());
},
BatchSize::SmallInput,
);
Expand All @@ -48,11 +47,11 @@ fn node_set_consecutive(c: &mut Criterion) {
c.bench_function("node set 1000 consecutive", |b| {
b.to_async(AsyncStdExecutor).iter_batched(
|| {
let mut store = MemoryBlockStore::default();
let store = MemoryBlockStore::default();
let operations =
operations(any::<[u8; 32]>(), any::<u64>(), 1000).sample(&mut runner);
let node = async_std::task::block_on(async {
node_from_operations(&operations, &mut store).await
node_from_operations(&operations, &store).await
})
.expect("Couldn't setup HAMT node from operations");

Expand All @@ -61,7 +60,8 @@ fn node_set_consecutive(c: &mut Criterion) {
},
|(mut node, store, kvs)| async move {
for (key, value) in kvs {
black_box(node.set(key, value, &store).await.unwrap());
node.set(key, value, &store).await.unwrap();
black_box(());
}
},
BatchSize::SmallInput,
Expand All @@ -70,14 +70,14 @@ fn node_set_consecutive(c: &mut Criterion) {
}

fn node_load_get(c: &mut Criterion) {
let mut store = MemoryBlockStore::default();
let store = MemoryBlockStore::default();
let cid = async_std::task::block_on(async {
let mut node = Rc::new(<Node<_, _>>::default());
for i in 0..50 {
node.set(i.to_string(), i, &store).await.unwrap();
}

let encoded_hamt = dagcbor::async_encode(&Hamt::with_root(node), &mut store)
let encoded_hamt = dagcbor::async_encode(&Hamt::with_root(node), &store)
.await
.unwrap();

Expand All @@ -102,14 +102,14 @@ fn node_load_get(c: &mut Criterion) {
}

fn node_load_remove(c: &mut Criterion) {
let mut store = MemoryBlockStore::default();
let store = MemoryBlockStore::default();
let cid = async_std::task::block_on(async {
let mut node = Rc::new(<Node<_, _>>::default());
for i in 0..50 {
node.set(i.to_string(), i, &store).await.unwrap();
}

let encoded_hamt = dagcbor::async_encode(&Hamt::with_root(node), &mut store)
let encoded_hamt = dagcbor::async_encode(&Hamt::with_root(node), &store)
.await
.unwrap();

Expand All @@ -131,14 +131,14 @@ fn node_load_remove(c: &mut Criterion) {
}

fn hamt_load_decode(c: &mut Criterion) {
let mut store = MemoryBlockStore::default();
let store = MemoryBlockStore::default();
let (cid, bytes) = async_std::task::block_on(async {
let mut node = Rc::new(<Node<_, _>>::default());
for i in 0..50 {
node.set(i.to_string(), i, &store).await.unwrap();
}

let encoded_hamt = dagcbor::async_encode(&Hamt::with_root(node), &mut store)
let encoded_hamt = dagcbor::async_encode(&Hamt::with_root(node), &store)
.await
.unwrap();

Expand Down Expand Up @@ -167,14 +167,14 @@ fn hamt_set_encode(c: &mut Criterion) {
Rc::new(<Node<_, _>>::default()),
)
},
|(mut store, mut node)| async move {
|(store, mut node)| async move {
for i in 0..50 {
node.set(i.to_string(), i, &store).await.unwrap();
}

let hamt = Hamt::with_root(node);

let _ = black_box(dagcbor::async_encode(&hamt, &mut store).await.unwrap());
let _ = black_box(dagcbor::async_encode(&hamt, &store).await.unwrap());
},
BatchSize::SmallInput,
)
Expand All @@ -187,20 +187,20 @@ fn hamt_diff(c: &mut Criterion) {
c.bench_function("hamt diff", |b| {
b.to_async(AsyncStdExecutor).iter_batched(
|| {
let mut store = MemoryBlockStore::default();
let store = MemoryBlockStore::default();
let kvs1 = generate_kvs("[a-z0-9]{1,3}", 0u64..1000, 0..100).sample(&mut runner);
let kvs2 = generate_kvs("[a-z0-9]{1,3}", 0u64..1000, 0..100).sample(&mut runner);
let (node1, node2) = task::block_on(async {
(
node_from_kvs(kvs1, &mut store).await.unwrap(),
node_from_kvs(kvs2, &mut store).await.unwrap(),
node_from_kvs(kvs1, &store).await.unwrap(),
node_from_kvs(kvs2, &store).await.unwrap(),
)
});
(store, (node1, node2))
},
|(mut store, (node1, node2))| async move {
|(store, (node1, node2))| async move {
black_box(
diff(Link::from(node1), Link::from(node2), &mut store)
diff(Link::from(node1), Link::from(node2), &store)
.await
.unwrap(),
);
Expand All @@ -216,24 +216,24 @@ fn hamt_merge(c: &mut Criterion) {
c.bench_function("hamt merge", |b| {
b.to_async(AsyncStdExecutor).iter_batched(
|| {
let mut store = MemoryBlockStore::default();
let store = MemoryBlockStore::default();
let kvs1 = generate_kvs("[a-z0-9]{1,3}", 0u64..1000, 0..100).sample(&mut runner);
let kvs2 = generate_kvs("[a-z0-9]{1,3}", 0u64..1000, 0..100).sample(&mut runner);
let (node1, node2) = task::block_on(async {
(
node_from_kvs(kvs1, &mut store).await.unwrap(),
node_from_kvs(kvs2, &mut store).await.unwrap(),
node_from_kvs(kvs1, &store).await.unwrap(),
node_from_kvs(kvs2, &store).await.unwrap(),
)
});
(store, (node1, node2))
},
|(mut store, (node1, node2))| async move {
|(store, (node1, node2))| async move {
black_box(
merge(
Link::from(node1),
Link::from(node2),
|a, b| Ok(cmp::min(*a, *b)),
&mut store,
&store,
)
.await
.unwrap(),
Expand Down
Loading