Skip to content

fix(incentive): reject high-s ECDSA signatures off-chain (#836) - #871

Merged
thiras merged 1 commit into
mainfrom
fix/836-reject-high-s-signatures
Jun 10, 2026
Merged

thiras merged 1 commit into
mainfrom
fix/836-reject-high-s-signatures

Conversation

@thiras

@thiras thiras commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

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 OpenZeppelin ECDSA.tryRecover rejects them with InvalidSignatureS. This asymmetry is exploitable:

  • A malicious client signs a voucher with a high-s value. The node accepts it (serves bytes, advances last_nonce), but closeChannel/withdraw revert at settlement. The replay guard (nonce > last_nonce) means no low-s replacement can ever be obtained for that nonce → accrued value is permanently unsettleable (free delivery / settlement griefing).
  • The same gap silently weakened slash evidence on the probe/stream paths (high-s slash_sig verifies off-chain, fails at the on-chain SlashJudge).

Fix

Add sig_canon::is_high_s, built on Signature::normalize_s() (returns Some iff s > n/2), and reject high-s before 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 (covers channel.rs:apply_voucher transitively)
  • bind_sig.rs:verify_binding → BindError::Malformed
  • probe_sig.rs / stream_sig.rs:recover_signer → …SlashError::InvalidSignature

No 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-s rejection 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 pins s == n/2 as canonical (matching OZ's strictly-greater-than rule). A channel-layer test locks the transitive apply_voucher path.

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 NonCanonicalS error 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

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]>
Copilot AI review requested due to automatic review settings June 10, 2026 17:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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_canon helper (is_high_s) and reject high-s signatures 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-s twin recovers the same signer, and a boundary test for s == n/2.
  • Add a channel-layer test to ensure apply_voucher rejects high-s vouchers 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

@github-actions

Copy link
Copy Markdown

Coverage report

Total: 85.85% (was 85.81%, ▲ +0.04%) — 34185/39818 lines

File Coverage Lines Δ
crates/incentive/src/bind_sig.rs 97.27% 107/110 ▲ +0.46%
crates/incentive/src/channel.rs 96.22% 382/397 ▲ +0.14%
crates/incentive/src/probe_sig.rs 98.71% 230/233 ▲ +0.08%
crates/incentive/src/sig_canon.rs 100.00% 37/37 new
crates/incentive/src/stream_sig.rs 99.16% 235/237 ▲ +0.05%
crates/incentive/src/voucher.rs 99.27% 271/273 ▲ +0.05%
History
Commit Total Δ vs base
33b252b (HEAD) 85.85% ▲ +0.04%

@thiras
thiras merged commit c5d3ce0 into main Jun 10, 2026
21 checks passed
@thiras
thiras deleted the fix/836-reject-high-s-signatures branch June 10, 2026 17:11
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.

incentive: high-s signature malleability asymmetry — vouchers accepted off-chain are unsettleable on-chain (free delivery / settlement griefing)

2 participants