Skip to content

fix(transaction): make Verify recover-and-compare, fail-closed#15

Open
ety001 wants to merge 1 commit into
masterfrom
fix/signed-tx-verify-recover
Open

fix(transaction): make Verify recover-and-compare, fail-closed#15
ety001 wants to merge 1 commit into
masterfrom
fix/signed-tx-verify-recover

Conversation

@ety001

@ety001 ety001 commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the [中] signature verification bypass finding in steem-audit/projects/steemutil/audit-reports/2026-07-code-scan.md.

SignedTransaction.Verify built an empty slice and iterated over that instead of tx.Signatures, so the loop body never ran and the method returned (true, nil) for any input — no signatures, garbage signatures, signatures over a tampered digest, all passed.

Fix

Rewrite as recover-and-compare: recover each signer's pubkey from the compact signature via ecdsa.RecoverCompact and compare to the expected key. This is the same verified mechanism already used in wif.PublicKey.VerifySha256.

Note: the audit report's suggested patch used ecdsa.ParseSignature(sig).Verify(...). That cannot work here — Sign() emits compact/recoverable signatures (ecdsa.SignCompact), while ParseSignature only parses DER. Even with correct iteration the report's patch would always fail. Recover-and-compare is the only correct approach.

Verify is now fail-closed: empty sigs, count mismatch, malformed hex, bad compact format, recovery failure, key mismatch → (false, error).

Test

  • Existing TestTransaction_SignAndVerify still passes (positive path).
  • New TestTransaction_VerifyNegativeCases: tampered digest, empty signatures, wrong pubkey, malformed signature (all return false), plus a baseline sanity check.
go test ./...   # all green
go vet ./...    # clean

Refs: steem-audit/projects/steemutil/audit-reports/2026-07-code-scan.md

SignedTransaction.Verify iterated over an empty slice instead of
tx.Signatures, so the verification loop body never executed and the
method unconditionally returned (true, nil) for any input — including
transactions with no signatures, garbage signatures, or signatures
over a tampered digest.

Rewrite Verify to recover each signer's public key from the compact
(recoverable) signature via ecdsa.RecoverCompact and compare it to the
expected pubkey. This matches the codebase's existing verified path
(wif.PublicKey.VerifySha256). Sign() emits compact signatures, so the
previous DER-based ecdsa.ParseSignature approach in the audit fix
suggestion could never have worked even with correct iteration.

Verify is now fail-closed: empty signatures, pubkey/signature count
mismatch, malformed hex, bad compact-signature format, recovery
failure, and key mismatch all return (false, non-nil error).

Add TestTransaction_VerifyNegativeCases covering tampered digest,
empty signatures, wrong pubkey, and malformed signature, plus a
baseline sanity check.

Refs: steem-audit/projects/steemutil/audit-reports/2026-07-code-scan.md (finding [中])
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.

1 participant