Skip to main content

Module ec

Module ec 

Source
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]