AltBn128
AltBn128
This file documents a contract which is not yet deployed to Mainnet.
Implementations of common elliptic curve operations on Ethereum's (poorly named) alt_bn128 curve. Whenever possible, use post-Byzantium pre-compiled contracts to offset gas costs. Note that these pre-compiles might not be available on all (eg private) chains.
G1Point
gfP2
G2Point
p
g1x
Gets generator of G1 group. Taken from go-ethereum/crypto/bn256/cloudflare/curve.go
g1y
g2xx
Gets generator of G2 group. Taken from go-ethereum/crypto/bn256/cloudflare/twist.go
g2xy
g2yx
g2yy
twistBx
Gets twist curve B constant. Taken from go-ethereum/crypto/bn256/cloudflare/twist.go
twistBy
hexRootX
Gets root of the point where x and y are equal.
hexRootY
g1YFromX
g1YFromX computes a Y value for a G1 point based on an X value. This computation is simply evaluating the curve equation for Y on a given X, and allows a point on the curve to be represented by just an X value + a sign bit.
g1HashToPoint
Hash a byte array message, m, and map it deterministically to a point on G1. Note that this approach was chosen for its simplicity and lower gas cost on the EVM, rather than good distribution of points on G1.
g1Decompress
Decompress a point on G1 from a single uint256.
g1Add
Wraps the point addition pre-compile introduced in Byzantium. Returns the sum of two points on G1. Revert if the provided points are not on the curve.
isG1PointOnCurve
Returns true if G1 point is on the curve.
scalarMultiply
Wraps the scalar point multiplication pre-compile introduced in Byzantium. The result of a point from G1 multiplied by a scalar should match the point added to itself the same number of times. Revert if the provided point isn't on the curve.
pairing
Wraps the pairing check pre-compile introduced in Byzantium. Returns the result of a pairing check of 2 pairs (G1 p1, G2 p2) (G1 p3, G2 p4)
getP
g1
g2
g2YFromX
g2YFromX computes a Y value for a G2 point based on an X value. This computation is simply evaluating the curve equation for Y on a given X, and allows a point on the curve to be represented by just an X value + a sign bit.
g1Compress
Compress a point on G1 to a single uint256 for serialization.
g2Compress
Compress a point on G2 to a pair of uint256 for serialization.
g1Unmarshal
Unmarshals a point on G1 from bytes in an uncompressed form.
g1Marshal
Marshals a point on G1 to bytes form.
g2Unmarshal
Unmarshals a point on G2 from bytes in an uncompressed form.
g2Decompress
Decompress a point on G2 from a pair of uint256.
gfP2Add
Returns the sum of two gfP2 field elements.
gfP2Multiply
Returns multiplication of two gfP2 field elements.
gfP2Pow
Returns gfP2 element to the power of the provided exponent.
gfP2Square
gfP2Cube
gfP2CubeAddTwistB
g2X2y
Returns true if G2 point's y^2 equals x.
isG2PointOnCurve
Returns true if G2 point is on the curve.
Last updated