![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
vrf-solidity
Advanced tools
vrf-solidity
is an open source fast and effective implementation of Verifiable Random Functions (VRFs) written in Solidity. More precisely, this library implements verification functions for VRF proofs based on the Elliptic Curve (EC) Secp256k1
.
DISCLAIMER: This is experimental software. Use it at your own risk!
The solidity library has been designed aiming at decreasing gas consumption and its complexity due to EC operations.
It provides two main pure
functions for verifying VRF proofs:
[pubKey-x, pubKey-y]
[gamma-x, gamma-y, c, s]
ecrecover
precompiled function to verify EC multiplications (lower gas consumption).[pubKey-x, pubKey-y]
[gamma-x, gamma-y, c, s]
u
EC point defined as U = s*B - c*Y
v
as V = s*H - c*Gamma
Additionally, the library provides some auxiliary pure
functions to facilitate computing the aforementioned input parameters:
[gamma-x, gamma-y, c, s]
[point-x, point-y]
[pubKey-x, pubKey-y]
[gamma-x, gamma-y, c, s]
([uPointX, uPointY], [sHX, sHY, cGammaX, cGammaY])
Secp256k1
)This library follows the algorithms described in VRF-draft-04 in order to provide the VRF verification capability.
The supported cipher suite is SECP256K1_SHA256_TAI
, i.e. the aforementioned algorithms using SHA256
as digest function and the secp256k1
curve. For the VRF algorithms the cipher suite code used is 0xFE
.
For elliptic curve arithmetic operations vrf-solidity
uses the elliptic-curve-solidity
library.
VRF.sol
library can be used directly by importing it.
Similarly to the VRFTestHelper.sol
from the test
project folder, a contract may use the library by instantiation as follows:
pragma solidity 0.6.12;
import "vrf-solidity/contracts/VRF.sol";
contract VRFTestHelper {
function functionUsingVRF(
uint256[2] memory public _publicKey,
uint256[4] memory public _proof,
bytes memory _message)
public returns (bool)
{
return VRF.verify(_publicKey, _proof, _message);
}
}
The tests under the test
folder can be seen as additional examples for interacting with the contract using Solidity and Javascript.
Gas consumption analysis was conducted in order to understand the associated costs to the usage of the vrf-solidity
library. Only public
functions were object of study as they are the only functions meant to be called by other parties.
The three auxiliary public functions (decodeProof
, decodePoint
and computeFastVerifyParams
) are recommended to be used (if possible) as off-chain operations, so that there is not gas costs.
Gas consumption and USD price estimation with a gas price of 100 Gwei, derived from ETH Gas Station:
·--------------------------------------------|---------------------------|-------------|----------------------------·
| Solc version: 0.6.12+commit.27d51765 · Optimizer enabled: true · Runs: 200 · Block limit: 6718946 gas │
·············································|···························|·············|·····························
| Methods · 100 gwei/gas · 590.98 usd/eth │
·················|···························|·············|·············|·············|··············|··············
| Contract · Method · Min · Max · Avg · # calls · usd (avg) │
·················|···························|·············|·············|·············|··············|··············
| VRF · computeFastVerifyParams · 1513058 · 1831274 · 1611989 · 91 · 95.27 │
·················|···························|·············|·············|·············|··············|··············
| VRF · decodePoint · 55844 · 55877 · 55867 · 10 · 3.30 │
·················|···························|·············|·············|·············|··············|··············
| VRF · decodeProof · 56839 · 56860 · 56851 · 10 · 3.36 │
·················|···························|·············|·············|·············|··············|··············
| VRF · fastVerify · 106360 · 352838 · 150715 · 94 · 8.91 │
·················|···························|·············|·············|·············|··············|··············
| VRF · gammaToHash · 24189 · 24201 · 24198 · 91 · 1.43 │
·················|···························|·············|·············|·············|··············|··············
| VRF · verify · 1543493 · 1862450 · 1643712 · 92 · 97.14 │
·--------------------------------------------|-------------|-------------|-------------|--------------|-------------·
The following resources have been used for test vectors:
Secp256k1
: Chuck BatsonSECP256K1_SHA256_TAI
: vrf-rsSome EC arithmetic operations have been opmitized thanks to the impressive work of the following resources:
vrf-rs
is published under the MIT license.
FAQs
Verifiable Random Function (VRF) library written in Solidity
We found that vrf-solidity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.