-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Problem
Contract keys in Freenet are derived from hash(parameters + contract_code). When different components use different versions of the same contract WASM, they compute different contract keys, causing operations to fail with "contract not found" errors.
Recent Incident
The multi-peer test in cli/tests/message_flow.rs was failing because:
- The test used
include_bytes!("../contracts/room_contract.wasm")(stale copy) - The
riverctlbinary usedinclude_bytes!(concat!(env!("OUT_DIR"), "/room_contract.wasm"))from build.rs - build.rs prioritizes
ui/public/contracts/room_contract.wasm
When these files drifted out of sync, the test would:
- Create a room (PUT with contract key A)
- Reconstruct the contract key using stale WASM (contract key B)
- Try to GET/Subscribe to key B → NotFound
Fixed in c28ffef by pointing the test to the canonical source.
Broader Concern
This pattern could cause issues in production:
- Different River builds (UI vs CLI) deployed with different contract WASM versions
- Users trying to join rooms created with a different version
- Any component that reconstructs contract keys must use identical WASM
Current Mitigations
cli/build.rshasverify_matches_built_artifact()that checks against release WASM.github/workflows/check-cli-wasm.ymlchecks for drift in CIcargo make sync-cli-wasmtask to manually sync
Potential Solutions
-
Single source of truth: Remove all copies, always build and reference from one location
-
Hash-based verification: At runtime, verify the WASM hash matches expected value before using it for key derivation
-
Contract registry: Store contract code hashes in a manifest that all components reference
-
Compile-time check: Macro that verifies WASM hashes match at compile time across crates
-
Version embedding: Embed a version/hash in the contract that can be queried
Impact
Without addressing this systematically:
- Silent failures when components drift
- Hard-to-debug "contract not found" errors
- Production rooms becoming inaccessible after updates
[AI-assisted - Claude]