Skip to content
Developer Handbook

Protocol reference

Cryptography behind a BCH payment

On this page

The wallet multiplies its private key by a fixed curve point to get the public key. It hashes that public key to build the P2PKH locking script and signs a digest when it spends the UTXO. The calculations below use the keys, hashes, and signature from the P2PKH stack trace.

Field arithmetic and public keys

secp256k1 uses the curve y² ≡ x³ + 7 (mod p) over the prime field p = 2²⁵⁶ − 2³² − 977. The points, together with the point at infinity, form a group. The specification fixes a generator G of prime order n. Coordinates are taken modulo p. Scalars that multiply G are taken modulo n. SEC 2 curve parameters

To add points A and B with different x coordinates, take λ = (yᵦ − yₐ) / (xᵦ − xₐ) in the field. Then x₃ = λ² − xₐ − xᵦ and y₃ = λ(xₐ − x₃) − yₐ. Division is multiplication by a modular inverse. To double a point with nonzero y, use the tangent slope 3xₐ² / (2yₐ). Adding opposite points gives the identity.

For a private scalar d with 1 ≤ d < n, the public key is P = dG. Repeated doubling and addition compute P efficiently. Recovering d from P is the elliptic-curve discrete logarithm problem. A compressed public key stores x and one byte selecting the y parity. The example's prefix 03 selects odd y. Public and private keys

What the hashes commit to

OperationConstructionRole in the example
Public-key hashRIPEMD160(SHA256(publicKeyBytes))OP_HASH160 computes it. The locking script compares it to b2557abfebaf263824b75ec473fd7b3db74957ea.
Transaction IDSHA256(SHA256(transactionBytes)), displayed with byte order reversedNames a transaction. An outpoint adds an output index.
Electrum lookupreverse(SHA256(lockingBytecode)) encoded in hexLets a client query the index by script.
Signature digestSHA256(SHA256(signingSerialization))Commits to the fields selected by the input's sighash type.

The P2PKH example’s signature ends with 0x41, meaning SIGHASH_ALL | SIGHASH_FORKID. The signing serialization commits to all the new outputs and includes the source value and relevant locking bytecode for the input being signed. The signed transaction ID hashes the serialized transaction including its unlocking bytecode. BCH signing serialization

Verify a BCH Schnorr signature

The 64 signature bytes encode two unsigned big-endian integers r and s, 32 bytes each. Let m be the 32-byte signing digest, P the public point, and compress(P) its 33-byte compressed encoding.

  1. Check that the public key is a valid point and that 0 ≤ r < p and 0 ≤ s < n.
  2. Compute e = int(SHA256(r_bytes || compress(P) || m)) mod n, interpreting the hash as big-endian. The || marks byte concatenation.
  3. Compute R′ = sG − eP. It must be a finite point, its x coordinate must equal r, and its y coordinate must have Jacobi symbol 1 modulo p. This selects the y coordinate that is a nonzero square in the field.

The signer chooses a private nonce scalar k with its sign adjusted to select that y coordinate. Then r = x(kG) and s = (k + ed) mod n. This gives the verification identity sG − eP = (k + ed)G − e(dG) = kG. Use maintained signing libraries for real keys. Reusing a nonce across two different challenges exposes the private scalar. BCH's verifier uses the compressed public key and the Jacobi rule described above. BCH Schnorr specification

Check the payment signature on Mocknet

These hex values come from the 219-byte signed payment in chapter 4. Treat each number as big-endian. Use the compressed public key pushed by the input to reproduce the challenge.

m · signing digest
6ec062b974c8098c5fffea7829f7745f80374ce11cad3ec73fa6addb8defa5ea
r · x coordinate
5fd87feafcd53fbd3c282e8f07f82fde8c4baa460a428bd88c9cd884a96e592d
s · signature scalar
b7f34f23361abfcc59f1a6de94edb0c3f753097766852c3235dcdd89047faf4f
e · challenge scalar
9f48aa72da27720977130f338833d15a6a8a99143287975a3ecb3ca9305114a5

Compare ECDSA on the same curve

ECDSA also uses P = dG. Its signature relation is s ≡ k⁻¹(z + rd) (mod n), with r = x(kG) mod n and z the message digest interpreted as an integer for this curve. A verifier computes Q = (zs⁻¹)G + (rs⁻¹)P and checks that it is finite and x(Q) mod n = r, with the applicable range and encoding checks. BCH's ECDSA transaction signature uses DER encoding followed by the sighash byte. Signature reference