This smart contract saves results of groth16 verifications.
Ensure near-shell
is installed by running:
near --version
If needed, install near-shell
:
npm install near-shell -g
Clone repos and move to feature/alt_bn128 branches
git clone https://github.com/zeropoolnetwork/nearcore.git
cd nearcore
git checkout feature/alt_bn128
make build
cd ..
git clone https://github.com/zeropoolnetwork/near-sdk-rs.git
cd near-sdk-rs
git checkout feature/alt_bn128
cd ..
git clone https://github.com/zeropoolnetwork/near-groth16-verifier.git
cd near-groth16-verifier
To make the build process compatible with multiple operating systems, the build process exists as a script in package.json
.
There are a number of special flags used to compile the smart contract into the wasm file.
Run this command to build and place the wasm file in the res
directory:
npm run build
Note: Instead of npm
, users of yarn may run:
yarn build
Build and deploy this smart contract to a development account. This development account will be created automatically and is not intended to be permanent. Please see the "Standard deploy" section for creating a more personalized account to deploy to.
nearup localnet --binary-path ../nearcore/target/release --overwrite
ln -s ~/.near/localnet/node0/validator_key.json ~/.near/validator_key.json
export NEAR_ENV=local
near dev-deploy --wasmFile res/near_groth16_verifier.wasm --masterAccount node0
Behind the scenes, this is creating an account and deploying a contract to it. On the console, notice a message like:
Done deploying to dev-1234567890123
In this instance, the account is dev-1234567890123
. A file has been created containing the key to the account, located at neardev/dev-account
. To make the next few steps easier, we're going to set an environment variable containing this development account id and use that when copy/pasting commands.
Run this command to the environment variable:
source neardev/dev-account.env
You can tell if the environment variable is set correctly if your command line prints the account name after this command:
echo $CONTRACT_NAME
The next command will call the contract's groth16verify_log
method:
near call $CONTRACT_NAME groth16verify_log '{"vk":"yO5EICtE+JVjTbRYkayI0Y/BoOJtE9lsrqeCTKTDnxD8UjB8B51wrVsQsVrsi6Uk0b2UKGfs3AJUX2Eud5wnET/ze/CsefR74bOn50BmVoExPPDiJGRD2IejItInd/wbtAH7GstyB1Q1j9uROBBAgE2eEj/cwRcHJobe4MP1mQIsiHdC5KXrBZFMlcRQi19O5pRHJ3fra+CNrckf5PHVL1NDT3E4ah/xGoRIbB0DfMSC2AO5NCyuZzJi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ClszrtTa/MGicksQVWpir/QNW/hp3N50wmjr1CUHvGP6u6WnrdK7oRDtSHgjcjmUVyr8NQtA06gcVk9m3KPdmWele0Bx9AcLpToixRb2FCx/JQ=="}' --accountId $CONTRACT_NAME
This data corresponds to withdrawal proof for simple mixer. Serialization from ethereum JSON to base64 is described at the test.
To retrieve the result of 1st call to the contract, call get_call
with the following:
near view $CONTRACT_NAME get_call '{"n":0}'
You should get true
as a result.
To test run:
cargo test -- --nocapture