Expand description
EC codegen — secp256k1 elliptic curve operations for Bitcoin Script.
Port of packages/runar-compiler/src/passes/ec-codegen.ts. All helpers are self-contained.
Point representation: 64 bytes (x[32] || y[32], big-endian unsigned). Internal arithmetic uses Jacobian coordinates for scalar multiplication.
Functions§
- emit_
ec_ add - ecAdd: add two points. Stack in: [point_a, point_b] (b on top) Stack out: [result_point]
- emit_
ec_ encode_ compressed - ecEncodeCompressed: point -> 33-byte compressed pubkey. Stack in: [point (64 bytes)] Stack out: [compressed (33 bytes)]
- emit_
ec_ make_ point - ecMakePoint: (x: bigint, y: bigint) -> Point. Stack in: [x_num, y_num] (y on top) Stack out: [point_bytes (64 bytes)]
- emit_
ec_ mod_ reduce - ecModReduce: ((value % mod) + mod) % mod Stack in: [value, mod] Stack out: [result]
- emit_
ec_ mul - ecMul: scalar multiplication P * k. Stack in: [point, scalar] (scalar on top) Stack out: [result_point]
- emit_
ec_ mul_ gen - ecMulGen: scalar multiplication G * k. Stack in: [scalar] Stack out: [result_point]
- emit_
ec_ negate - ecNegate: negate a point (x, p - y). Stack in: [point] Stack out: [negated_point]
- emit_
ec_ on_ curve - ecOnCurve: check if point is on secp256k1 (y^2 = x^3 + 7 mod p). Stack in: [point] Stack out: [boolean]
- emit_
ec_ point_ x - ecPointX: extract x-coordinate from Point. Stack in: [point (64 bytes)] Stack out: [x as bigint]
- emit_
ec_ point_ y - ecPointY: extract y-coordinate from Point. Stack in: [point (64 bytes)] Stack out: [y as bigint]