Repository navigation
fix(incentive): reject high-s ECDSA signatures off-chain (#836) - #871
Conversation
Off-chain voucher/slash/binding verification used alloy's `recover_address_from_prehash`, which silently normalizes and accepts high-`s` (non-canonical) signatures. On-chain OpenZeppelin `ECDSA.tryRecover` rejects them with `InvalidSignatureS`. A malicious client could exploit the asymmetry: a high-`s` voucher is accepted off-chain (bytes served, `last_nonce` advanced) but reverts at `closeChannel`/`withdraw`, and the replay guard blocks ever obtaining a low-`s` replacement — leaving the accrued value permanently unsettleable (free delivery / settlement griefing). The same gap silently weakened slash evidence on the probe/stream paths. Add `sig_canon::is_high_s` (built on `Signature::normalize_s`, which is `Some` iff `s > n/2`) and reject high-`s` before recovery at every off-chain verification site: voucher, channel (transitive), binding, and probe/stream slash. This makes the off-chain accept-set exactly match the on-chain verifiable-set. No contract changes — the on-chain side was already correct. Tests: high-`s` rejection at each site plus a helper-anchoring test that proves the malleable twin recovers the same signer (so the rejections isolate canonicalization, not a malformed signature) and a boundary test pinning `s == n/2` as canonical. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR closes #836 by ensuring off-chain ECDSA verification in crates/incentive rejects non-canonical high-s signatures, eliminating an accept-set mismatch where the node would accept signatures that OpenZeppelin rejects on-chain (leading to unsettleable vouchers and weakened slash evidence).
Changes:
- Add a shared
sig_canonhelper (is_high_s) and reject high-ssignatures prior to recovery across voucher/binding/probe/stream verification sites. - Add regression tests per verification site plus a helper-anchoring test to prove the malleable high-
stwin recovers the same signer, and a boundary test fors == n/2. - Add a channel-layer test to ensure
apply_voucherrejects high-svouchers transitively without mutating state.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| crates/incentive/src/sig_canon.rs | Introduces canonical-s detection and a test-only high-s twin helper with anchoring/boundary tests. |
| crates/incentive/src/lib.rs | Registers the new sig_canon module for crate-internal reuse. |
| crates/incentive/src/voucher.rs | Rejects high-s vouchers before recovery and adds a targeted regression test. |
| crates/incentive/src/channel.rs | Adds a channel-level regression test ensuring apply_voucher rejects high-s without advancing last_nonce. |
| crates/incentive/src/bind_sig.rs | Rejects high-s bindings and adds a regression test for the binding path. |
| crates/incentive/src/probe_sig.rs | Rejects high-s probe slash signatures and adds a regression test. |
| crates/incentive/src/stream_sig.rs | Rejects high-s stream slash signatures and adds a regression test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request introduces canonical-s signature enforcement for off-chain ECDSA signature verification to prevent asymmetry with on-chain verification (which rejects high-s signatures). A new sig_canon module is added to detect high-s signatures. Verification logic in bind_sig, probe_sig, stream_sig, and voucher has been updated to reject non-canonical high-s signatures, accompanied by comprehensive unit tests. There are no review comments to assess, and I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Coverage reportTotal: 85.85% (was 85.81%, ▲ +0.04%) — 34185/39818 lines
History
|
Summary
Closes #836 (
critical,security,poc-blocking).Off-chain ECDSA verification used alloy's
recover_address_from_prehash, which silently normalizes and accepts high-s(non-canonical) signatures. On-chain OpenZeppelinECDSA.tryRecoverrejects them withInvalidSignatureS. This asymmetry is exploitable:svalue. The node accepts it (serves bytes, advanceslast_nonce), butcloseChannel/withdrawrevert at settlement. The replay guard (nonce > last_nonce) means no low-sreplacement can ever be obtained for that nonce → accrued value is permanently unsettleable (free delivery / settlement griefing).sslash_sigverifies off-chain, fails at the on-chainSlashJudge).Fix
Add
sig_canon::is_high_s, built onSignature::normalize_s()(returnsSomeiffs > n/2), and reject high-sbefore recovery at every off-chain verification site so the off-chain accept-set exactly matches the on-chain verifiable-set:voucher.rs:recover_signer→VoucherError::InvalidSignature(coverschannel.rs:apply_vouchertransitively)bind_sig.rs:verify_binding→BindError::Malformedprobe_sig.rs/stream_sig.rs:recover_signer→…SlashError::InvalidSignatureNo contract changes — the on-chain side was already correct. The doc comments at these sites already named "non-canonical
s" as a rejection cause; this makes that true.Tests
156 tests pass (+9). Per-site high-
srejection tests assert the specific error variant. A helper-anchoring test proves the malleable twin(r, n−s, !v)recovers the same signer (so the rejections isolate canonicalization, not a malformed signature), and a boundary test pinss == n/2as canonical (matching OZ's strictly-greater-than rule). A channel-layer test locks the transitiveapply_voucherpath.Review
Reviewed by the multi-agent PR toolkit (code/tests/comments/error-handling): correct, complete, standards-compliant, no blocking issues. The two test-quality findings (anchor the twin helper; cover the channel-apply layer) are incorporated above.
Deliberately out of scope: a distinct
NonCanonicalSerror variant for richer operator diagnostics — the rejection is already a propagated typed error (not a silent failure), and the existing variant reuse keeps this critical fix tight. Candidate follow-up.Verification
```
cargo nextest run -p decdn-incentive # 156 passed
cargo clippy --workspace --all-targets # clean
cargo fmt -- --check # clean
cargo build # workspace builds
```
🤖 Generated with Claude Code