Tried to implement this trick with Solidity, but had no luck yet. Any suggestions? How v
should define y
's parity? Need this trick for split-key address generation.
UPDATE:
Fixed and fully working implementation for secp256k1
elliptic curve:
function ecmulVerify(uint256 x1, uint256 y1, uint256 scalar, uint256 qx, uint256 qy) public pure
returns(bool)
{
uint256 m = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141;
address signer = ecrecover(0, y1 % 2 != 0 ? 28 : 27, bytes32(x1), bytes32(mulmod(scalar, x1, m)));
address xyAddress = address(uint256(keccak256(abi.encodePacked(qx, qy))) & 0x00FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
return xyAddress == signer;
}
function publicKeyVerify(uint256 privKey, uint256 x, uint256 y) public pure
returns(bool)
{
uint256 gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798;
uint256 gy = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8;
return ecmulVerify(gx, gy, privKey, x, y);
}