Skip to content

fix(core): drop sync-multihash-sha2 and align piece size limits with commp-wasm - #1152

Open
hugomrdias wants to merge 1 commit into
masterfrom
hugomrdias/sync-multihash-sha2-core-3a177d
Open

hugomrdias wants to merge 1 commit into
masterfrom
hugomrdias/sync-multihash-sha2-core-3a177d

Conversation

@hugomrdias

Copy link
Copy Markdown
Member

What

  • Drop sync-multihash-sha2. Piece.merkle.computeNode now uses Hash.sha256 from ox, which is synchronous and already a core dependency (it uses @noble/hashes underneath). ROOT_SIZE is now the literal 32.
  • Piece.MAX_SIZE now matches the hasher. It re-exports commp-wasm's MAX_PAYLOAD_SIZE (127n << 47n, about 15.9 PiB). It used to be a height-255 value (about 2^255 bytes).
  • Piece.MAX_HEIGHT is derived from MAX_SIZE. heightFor(MAX_SIZE) gives 49. It used to be 255.
  • Removed the unused split() from internal/merkle.ts and fixed an outdated comment in zero-comm.ts.

Why

PieceCID hashing (calculate, hasher, transformStream) already goes through commp-wasm. The only remaining user of sync-multihash-sha2 was the public Piece.merkle helpers, and nothing in the repo calls those outside tests. The package also has two problems:

  • Its ./sha256 export only defines browser and node conditions, with no default. Runtimes that match neither (for example some worker setups) can't resolve it.
  • Its node build imports node:crypto.

The old MAX_SIZE was larger than anything calculate accepts. A size that passed a check against MAX_SIZE could still make the hasher throw a RangeError. commp-wasm caps the size at 127 × 2^47 so that padding and piece size stay exact as JS numbers.

Reviewer notes

  • MAX_SIZE and MAX_HEIGHT are public constants and their values change. I've marked this as a fix because the old values were limits callers could never actually reach.
  • The generated reference docs under docs/ will pick up the new values when they're regenerated.
  • Tests: added coverage for both limits in test/piece.test.ts. The existing computeNode and zeroRoot vectors pass with ox. Core node and browser suites pass.

🤖 Generated with Claude Code

@github-project-automation github-project-automation Bot moved this to 📌 Triage in FOC Nov 19, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T19:00:28.769724Z bd226ab PR opened
🔒 Security Review ✅ Completed 2026-11-19T19:01:33.557392Z bd226ab PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

filecoin-encryption-envelope

npm i https://pkg.pr.new/filecoin-encryption-envelope@1152

@filoz/keysmith

npm i https://pkg.pr.new/@filoz/keysmith@1152

@filoz/synapse-core

npm i https://pkg.pr.new/@filoz/synapse-core@1152

@filoz/synapse-react

npm i https://pkg.pr.new/@filoz/synapse-react@1152

@filoz/synapse-sdk

npm i https://pkg.pr.new/@filoz/synapse-sdk@1152

commit: 148e54f

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Docs preview: https://pr-1152-synapse-dev.filoz.workers.dev

Built from 148e54f.

@FilOzzy FilOzzy moved this from 📌 Triage to 🔎 Awaiting review in FOC Nov 19, 2026
…commp-wasm

Use ox's synchronous Hash.sha256 for Piece.merkle.computeNode instead of
sync-multihash-sha2, whose ./sha256 export has no default condition and
whose node build imports node:crypto. PieceCID hashing already goes
through commp-wasm, so merkle helpers were the only consumer.

Piece.MAX_SIZE now re-exports commp-wasm's MAX_PAYLOAD_SIZE
(127 * 2^47 bytes) instead of the height-255 bound the hasher rejects,
and Piece.MAX_HEIGHT is derived from it (49 instead of 255).

Also remove the unused merkle split() helper and a stale zero-comm comment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hugomrdias
hugomrdias force-pushed the hugomrdias/sync-multihash-sha2-core-3a177d branch from bd226ab to 148e54f Compare November 20, 2026 19:26

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🔎 Awaiting review

Development

Successfully merging this pull request may close these issues.

1 participant