Skip to content

Reject upgrades of length 0 - #930

Merged
mafintosh merged 1 commit into
mainfrom
fix/empty-upgrade
Nov 4, 2026
Merged

mafintosh merged 1 commit into
mainfrom
fix/empty-upgrade

Conversation

@marcus-pousette-hp

Copy link
Copy Markdown
Contributor

Co-authored with AI

@marcus-pousette-hp
marcus-pousette-hp requested a review from a team November 4, 2026 17:59
@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5 Tier: apex

[Low impact] The change affects only proof upgrades with an empty range.

The PR appears safe to merge, with a non-blocking rejection gap for nonempty receivers.

Fix All in Claude CodeFindings

  1. P2 Zero-length proofs still pass ▶
Fix with agent prompt
### Issue 1
lib/merkle-tree.js:1070
`applyProof` can still accept a zero-length upgrade when the receiver already has data. With a receiver at length 1, the exact proof in the new test reaches `MerkleTree.refit` first. Refit removes the empty upgrade, so verification skips this check and returns `true`. Check the original upgrade length before refitting, and add a test with a nonempty receiver.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Adds a zero-length check in verifyUpgrade.

  • Proof checks reject upgrades that cover zero blocks.

Reviews (1) · Last reviewed commit: "Reject upgrades of length 0" · Reviewed by Greptile

Comment thread lib/merkle-tree.js
}

function verifyUpgrade({ fork, upgrade }, blockRoot, batch) {
if (upgrade.length === 0) throw INVALID_OPERATION('Invalid upgrade')

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Zero-length proofs still pass

applyProof can still accept a zero-length upgrade when the receiver already has data. With a receiver at length 1, the exact proof in the new test reaches MerkleTree.refit first. Refit removes the empty upgrade, so verification skips this check and returns true. Check the original upgrade length before refitting, and add a test with a nonempty receiver.

Knowledge Base Used:

Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/merkle-tree.js
Line: 1070

Comment:
**Zero-length proofs still pass**

`applyProof` can still accept a zero-length upgrade when the receiver already has data. With a receiver at length 1, the exact proof in the new test reaches `MerkleTree.refit` first. Refit removes the empty upgrade, so verification skips this check and returns `true`. Check the original upgrade length before refitting, and add a test with a nonempty receiver.

**Knowledge Base Used:**
- [Data integrity and Merkle verification](https://app.greptile.com/-/switch-tenant?tenant=tetherio&next=%2Fcustom-context%2Fknowledge-base%2Fholepunchto%2Fhypercore%2F-%2Fdocs%2Fdata-integrity.md)
- [Merkle tree operations](https://app.greptile.com/-/switch-tenant?tenant=tetherio&next=%2Fcustom-context%2Fknowledge-base%2Fholepunchto%2Fhypercore%2F-%2Fdocs%2Fmerkle-tree-operations.md)

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code

@mafintosh
mafintosh merged commit c9c0031 into main Nov 4, 2026
6 checks passed
@mafintosh
mafintosh deleted the fix/empty-upgrade branch November 4, 2026 19:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants