Solidity implementation of a twisted Edwards curve on scalar field of BN254, also known as Baby-Jubjub.
This repo was modified from:
- Another Solidity implementation: https://github.com/yondonfu/sol-baby-jubjub/blob/master/contracts/CurveBabyJubJub.sol
- Arkwork Rust implementation: https://github.com/arkworks-rs/curves/tree/master/ed_on_bn254
Base Field
Twisted edwards curve
Where
First, install this package as dependency.
forge install https://github.com/Tetration-Lab/solidity-ed-on-bn254
forge remappings
Then use it in library or smart contract.
import {EdOnBN254} from "solidity-ed-on-bn254/EdOnBN254.sol";
contract X {
function x() public {
EdOnBN254.Affine g = EdOnBN254.primeSubgroupGenerator(); // Prime subgroup generator
EdOnBN254.Affine x = EdOnBN254.mul(g, 3); // Scalar multiplication
EdOnBN254.Affine y = EdOnBN254.add(g, x); // Affine addition
EdOnBN254.Affine z = EdOnBN254.neg(y); // Affine negation
}
}