Proposes native curve arithmetic for contracts that need to manipulate elliptic-curve points and scalars.
Specification
Title: Native Elliptic Curve Arithmetic Operations
Type: Standards
Layer: Consensus
Maintainer: Jerry Qian (lightswarm)
Status: Draft / Experimental Benchmark
Initial Publication Date: 2025-05-23
Latest Revision Date: 2026-08-01
Version: 0.4.0
Abstract
The proposal has two core operations for native secp256k1 affine elliptic-curve arithmetic in BCH locking scripts:
OP_ECADDOP_ECMUL
The repository also contains three follow-on candidates that are being benchmarked separately:
OP_MODINVOP_ECMULTGENOP_ECMULTMULTI
The purpose of the proposal is to make the expensive curve calculations used by locking-script proofs and covenants practical, while keeping each consensus primitive small enough to specify, implement, benchmark, and audit. None of the five operations is activated on BCH. The Libauth implementation is an experimental research branch.
Motivation
The thread converged on a practical need, not just a general desire for more math:
- BCH locking scripts need point addition and scalar multiplication to validate EC relationships directly
- proof-carrying protocols, aggregate signatures, covenant logic, and custom cryptographic protocols benefit from native curve operations
- emulation in script is possible but far too expensive for real-world use
The discussion also made two requirements clear:
- the CHIP needs a real, concrete locking-script use case, not just toy examples
- the initial spec should stay focused instead of expanding into a large math package
Scope
Core scope
- affine point addition on secp256k1
- affine scalar multiplication on secp256k1
- deterministic failure on invalid inputs
- fixed-width 32-byte big-endian encodings
Follow-on candidates
- modular inversion in the secp256k1 field
- fixed-generator scalar multiplication
- bounded multi-scalar multiplication
These candidates have separate fixtures and measurements. They should not be treated as part of the core CHIP until their own safety and cost reviews pass.
Out of scope for this proposal
The following are intentionally not included in this CHIP:
- point negation as a separate opcode
- point doubling as a separate opcode
- point decompression
- pairings
- generic curve selection
- masked transfer balances or transaction-value confidentiality
These can be proposed later if there is a separate use case and implementation budget.
This proposal does not change transaction format or output visibility. It only adds EC math to locking-script evaluation.
Review Assets
- Logical fixtures cover canonical operand semantics for the core CHIP and follow-on candidates.
- VM fixtures cover bytecode-level consensus behavior for
OP_ECADDandOP_ECMUL. - CashScript emulation benchmarks exercise the proposed operations' workload using user-defined functions and ordinary integer arithmetic.
- CashScript emulation findings record VM costs, Mocknet/CHIPNET outcomes, and non-production boundaries.
- Proposal comparison maps ECADD, ECMUL, and the three addendum operations to the benchmark evidence.
- Costs, stacks, and practical uses gives the measured simulation/native comparison, a conservative pricing envelope, stack shapes, and concrete Alice/Bob/Carol examples.
- Differential and boundary results records the two-host Libauth/reference comparison, P2SH32 mutation matrix, and exact measured hashes.
- Operation vector records the source-derived worst-case arithmetic envelope and its review boundary.
- Technical addendum sketches candidate follow-on opcodes and remaining design questions.
- package.json and the lockfile make
npm installandnpm run validatefully turnkey, including the CashScript benchmark suite.
The benchmark is deliberately separate from the normative fixture sets. It does not change the CashScript compiler, and it does not claim that the full-width emulated proofs fit current BCH per-input limits. Its purpose is to show, with executable evidence, what native EC operations would remove from the script's arithmetic workload.
Reproduce the native-opcode comparison
The native comparison uses an experimental modified Libauth fork. It does not
use the published @bitauth/libauth package or the upstream Libauth default
branch. Clone both public repositories and check out the exact Libauth
modification branch:
git clone https://github.com/lightswarm124/bch-ec-arithmetic.git
git clone https://github.com/lightswarm124/libauth.git
git -C libauth checkout prototype/ec-opcodes-secp256k1
node libauth/.yarn/releases/yarn-4.0.2.cjs install
node libauth/.yarn/releases/yarn-4.0.2.cjs build:tsc
cd bch-ec-arithmetic
npm install
npm run test:campaign
LIBAUTH_BUILD_ROOT=../libauth/build npm run benchmark:campaign
node benchmarks/campaign/render-report.mjs \
benchmarks/results/raw/$(hostname)/ec-verifier-ab.json
Public implementation references:
- Libauth experimental modification branch
- Experimental EC implementation
- Experimental EC cost profile
- EC opcode unit tests
The Libauth branch is an initial research implementation for benchmarking. It is not deployed BCH node behavior or a consensus-ready opcode implementation. The latest local measurements were built from the branch base commit plus an uncommitted working-tree diff. The public branch links identify the fork and branch, while each raw result records the exact source, diff, and build hashes needed to identify the measured code. Do not treat the public branch pointer alone as an exact reproduction of those latest results until the changes have been committed and pushed.
Definitions
The curve is secp256k1 over the field F_p where:
p = 2^256 - 2^32 - 977n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141Gis the standard secp256k1 generator
A point is represented in affine coordinates as (x, y) using 32-byte big-endian integers.
Canonical encoding
All field elements and scalars MUST be encoded as exactly 32 bytes.
- Field elements MUST satisfy
0 <= value < p - Scalars MUST satisfy
1 <= value < n
There is no compressed-point representation in this CHIP.
Stack notation
Stack items are listed top-to-bottom.
If an opcode pops A, then B, A is the topmost item.
Opcode Semantics
OP_ECADD
Inputs
Top-to-bottom stack inputs:
pointB_ypointB_xpointA_ypointA_x
Behavior
- Parse all four inputs as canonical 32-byte big-endian field elements.
- Fail if any input is not canonical or is greater than or equal to
p. - Interpret the inputs as affine secp256k1 points
A = (pointA_x, pointA_y)andB = (pointB_x, pointB_y). - Fail if either point is not on the secp256k1 curve.
- Compute
R = A + Bin the secp256k1 group. - Fail if
Ris the point at infinity. - Push the result coordinates back onto the stack.
Outputs
Top-to-bottom stack outputs:
result_yresult_x
OP_ECMUL
Inputs
Top-to-bottom stack inputs:
scalarpoint_ypoint_x
Behavior
- Parse
scalaras a canonical 32-byte big-endian integer. - Fail if
scalaris not canonical or is not in the range1 <= scalar < n. - Parse
point_xandpoint_yas canonical 32-byte big-endian field elements. - Fail if the point is not on the secp256k1 curve.
- Compute
R = scalar * point. - Fail if
Ris the point at infinity. - Push the result coordinates back onto the stack.
Outputs
Top-to-bottom stack outputs:
result_yresult_x
Consensus Rules
The following are consensus-critical:
- All implementations MUST use the same curve parameters and canonical encodings.
- Any invalid input MUST fail the opcode atomically.
- A failure MUST leave no partial outputs on the stack.
- The output of each opcode MUST be deterministic for the same input bytes.
- Points at infinity are not representable as successful results in this CHIP.
OP_ECADDandOP_ECMULfail when their final result is infinity.OP_ECMULTMULTImay use infinity internally as the accumulator identity, but MUST fail if its final result is infinity. This keeps the result independent of harmless cancellation order while never exposing an infinity encoding.
Implementations MAY use projective or Jacobian coordinates internally, but the consensus result MUST match the affine semantics above.
Resource Accounting
Native EC arithmetic is expensive enough that it MUST be explicitly metered.
- Every activated EC opcode MUST charge a deterministic consensus operation cost.
- The cost MUST be enforced by the VM operation-cost limit before expensive curve work begins.
- The cost MUST cover worst-case valid operands, validation, serialization, and failure-path work.
- Costs MUST be monotonic with the term count for
OP_ECMULTMULTI. - The exact constants MUST be benchmarked against an implementation-neutral operation model and independent implementations before activation.
OP_ECMULSHOULD cost at least as much asOP_ECADDunless a different bounded algorithm is specified and justified.
The experimental Libauth branch currently uses these diagnostic values:
| Operation | Prototype cost |
|---|---|
OP_ECADD |
4,600 |
OP_ECMUL |
37,100 |
OP_MODINV |
4,600 |
OP_ECMULTGEN |
37,100 |
OP_ECMULTMULTI(n) |
100 + 37,000n + 4,500(n-1) |
These figures are benchmark inputs, not activation recommendations.
If the chosen op-cost budget cannot support these operations safely, the CHIP should not activate.
Security Considerations
DoS resistance
The opcodes must be bounded by the VM cost meter so they cannot be used to create unbounded work.
Input validation
Consensus must reject:
- malformed 32-byte encodings
- field elements outside the secp256k1 field
- scalars outside the secp256k1 scalar range
- points not on the curve
- a final result at the point at infinity; an internal multi-scalar accumulator may temporarily be infinity as the group identity
Implementation safety
Reference code SHOULD use constant-time routines where practical.
That is an implementation requirement, not a consensus requirement, but it matters because these operations are cryptographic primitives and will likely be used in sensitive locking-script logic.
Scope control
The proposal keeps doubling, negation, equality, and subtraction out of the public opcode set because existing operations can express them without losing an important class of functionality. The expensive primitives are the ones that deserve consensus surface: general addition, scalar multiplication, and, if independently justified, fixed-base and bounded multi-scalar multiplication.
Reference Use Cases
The thread identified the first concrete use cases that justify the CHIP:
- EC commitment validation and covenant authorization logic
- MuSig-style aggregation and related threshold signing workflows
- proof-carrying locking-script protocols and other developer-defined script logic
- future EC-based proof components; pairing-based systems are a separate scope question
At least one end-to-end locking-script example SHOULD accompany the final CHIP submission so the network can evaluate a real BCH transaction use case, not just a toy example.
Test Vectors
The implementation test suite SHOULD include:
scalar = 2,point = G, expect2GpointA = G,pointB = 2G, expect3G- invalid point
(0x01, 0x01), expect failure scalar = 0, expect failurescalar = n, expect failurepointA = G,pointB = -G, expect failure because the result is infinity
See fixtures/README.md for machine-readable fixture sets covering the core CHIP and the addendum opcodes.
Those fixtures intentionally include boundary-value and failure cases for canonical encoding, invalid points, infinity, and multi-scalar count mismatches so implementers can exercise the consensus failure paths, not just the happy path.
See fixtures/vm/README.md for raw-bytecode execution fixtures that cover stack underflow, malformed pushes, and atomic failure behavior in the BCH VM.
Test vectors SHOULD be checked against a known-good secp256k1 implementation such as libsecp256k1.
Deployment status
There is no activation proposal in this repository. The branch is an experimental benchmark and review artifact.
Before activation, the open items include:
- final opcode numbering or opcode-family encoding
- exact op-cost constants for each activated operation
- implementation-neutral operation vectors
- independent implementation benchmark results, including older hardware
- a real locking-script example or covenant demonstrating practical utility
- complete differential, fuzz, failure-path, and whole-block testing
Opcode Namespace Proposal
Final codepoint allocation is intentionally deferred. A contiguous family block may be useful, but candidate byte values are placeholders until the active and reserved instruction sets are reviewed by the community. The proposal should define selector encoding, unknown-selector behavior, cost attachment, and curve-family separation before assigning codepoints.
These reserved bytes matter because the loop and function opcodes can make an emulation readable, but they do not change the arithmetic cost class. In practice, OP_DEFINE/OP_INVOKE and OP_BEGIN/OP_UNTIL only restructure the work that ECADD, ECMUL, and the addendum opcodes would otherwise remove.
Follow-on work
The repository evaluates OP_MODINV, OP_ECMULTGEN, and OP_ECMULTMULTI as
possible follow-on operations. Pairing support is outside this proposal and
would require a separate design and benchmark campaign.
This is actively being discussed in Bitcoin Cash Research thread
Technical Addendum
See TECHNICAL_ADDENDUM.md for candidate follow-on opcodes, their intended use cases, and a detailed sketch of how each one would be specified.
Peer-review summary
This section is the current proposal summary. It brings together the rules, measurements, examples, and open questions in one place so that the README can stand on its own when viewed on GitHub.
What the proposal is trying to do
The first two operations are OP_ECADD and OP_ECMUL on secp256k1. They are
intended to make public-point relationships practical inside BCH locking
scripts. Examples include commitment checks, custom key-management rules,
DLEQ-style relationships, and proof-carrying covenants.
OP_MODINV, OP_ECMULTGEN, and OP_ECMULTMULTI remain separate review items.
They may be useful, but they should not be treated as automatically justified
by the core proposal.
Every operation must use exact 32-byte big-endian operands, reject non-canonical field elements and scalars, validate curve membership before arithmetic, and fail without exposing a partial result. The point at infinity has no successful stack encoding. A final infinite result fails.
What has actually been measured
The current evidence comes from an experimental modified Libauth build and an independent affine secp256k1 reference implementation. The campaign ran on an i5-9400 home machine and an older i7-4770 chipnet machine.
It covered 157 valid cases, 24 invalid and boundary cases, 256 malformed raw stack cases, P2SH32 wrapping, transaction-context mutations, batch-count errors, inverse-point cases, lower-stack preservation, monotonic cost checks, and peak process memory.
Both machines produced the same operation costs. The measured
ECMULTMULTI sweep was:
| Terms | Operation cost |
|---|---|
| 1 | 37,692 |
| 2 | 79,588 |
| 4 | 163,380 |
| 8 | 330,964 |
| 16 | 666,132 |
| 32 | 1,336,468 |
All valid cases matched the independent reference. Invalid and malformed cases failed closed. Peak observed process RSS was about 100 MiB on the home machine and 102 MiB on the chipnet machine. These results support continued review; they are not an old-hardware guarantee or an activation recommendation.
The detailed reports are:
- Differential and boundary campaign
- Operation vector
- Worst-case campaign
- Costs, stacks, and practical uses
Simulation versus native operations
With the current VM, curve arithmetic can be written using integer operations, loops, helper functions, and repeated stack pushes. That is expressive, but the arithmetic, stack pressure, and VM dispatch all add up.
Once ECADD and ECMUL exist, generator multiplication can be expressed as a
generic multiplication by G, and a multi-scalar expression can be expanded
into separate scalar multiplications and additions. The current generic
ECMULTMULTI prototype saves only a small amount against that expansion:
| Terms | Difference from separate core operations |
|---|---|
| 2 | 200 cost units |
| 8 | 1,400 cost units |
| 32 | 6,200 cost units |
This is a useful warning. A bounded batch interface is not, by itself, a large
batching improvement. A stronger ECMULTMULTI case requires an optimized,
bounded algorithm and a new operation vector.
The isolated MODINV comparison measured 18,387–38,528 operation-cost units
for the selected scripted cases. A deliberately difficult 256-bit input took
154 Euclidean steps in the reference calculation. That shows why inversion
deserves separate attention, but it does not establish a universal worst-case
price.
Practical transaction patterns
These are protocol sketches, not finished contracts. Each still needs ordinary BCH checks for the source output, output index, value, token state, successor script, and replay behavior.
- Alice and Bob can approve a new spending key by having the locking script combine and compare public points derived from their agreed policy.
- Alice can commit to a value with a Pedersen-style relation such as
C = v*G + r*H, then revealvandrin a later spend. - Carol can check a DLEQ-style statement showing that two public points came from related secrets without learning those secrets.
- Alice, Bob, and Carol can use custom threshold or key-aggregation policies whose public-point equations are checked by the contract.
- A large proof can be divided across inputs, although splitting only helps if the proof and covenant are designed for it. Repeating the same verifier does not reduce the work on any one input.
Separate proof projects
The BCH-FRI-STARK-Verifier and ShieldKit projects are independent controls, not parts of this proposal.
BCH-FRI uses Goldilocks-field arithmetic, Poseidon hashing, Merkle paths, and FRI folding. Secp256k1 EC opcodes do not directly accelerate those operations. A useful FRI acceleration would need a separate Goldilocks, Poseidon, or FRI proposal.
ShieldKit explores BN254 Groth16 and pairing-based verification. BN254 is not secp256k1, and pairing arithmetic is not ordinary secp256k1 point addition or multiplication. Direct ShieldKit savings therefore require a separate BN254 or pairing proposal with its own encoding, cost model, memory bound, and tests.
These projects remain valuable for studying BCH transaction limits and multi-input verifier design. Their results must not be presented as measured savings from this secp256k1 proposal.
Questions for reviewers
- Is rejecting every successful infinity result the right consensus rule?
- Are exact 32-byte operands practical for the intended scripts?
- Are the atomic failure and lower-stack rules unambiguous?
- What bounded operation vector should determine each price?
- Should
MODINVstay separate from the core two operations? - Can
ECMULTGENreceive a fixed-base discount without creating a memory or implementation loophole? - What maximum term count and cost formula make
ECMULTMULTIsafe? - Which older implementations and hardware should be tested before activation?
- Is the opcode namespace unambiguous across all BCH instruction sets?
What remains before activation
The proposal still needs frozen codepoints and semantics, independent client implementations, worst-case pricing review, fuzzing with replay fixtures, complete transaction-level tests, older-hardware testing, memory review, and proof that existing BCH scripts are unchanged outside the intended instruction set.
Until those gates are met, the correct label is:
Experimental benchmark evidence; not a consensus cost recommendation.
References
- secp256k1
- Bitcoin Cash Research thread
- CHIP-2021-05 VM Limits
- EC verifier A/B campaign report
- Bitcoin Wiki: ECDSA
- libsecp256k1
Copyright
This document is placed in the public domain.