This demo shows how an ioTex device creates a local zero-knowledge proof of its location, which is verified on the iotex chain and, if successfully verified, then the owner of the device receives a reward.
This is necessary to sign the proof with the device's private key.
Follow https://github.com/iotexproject/ioID-SDK/tree/main/example/linux/deviceregister/doc
If on a Mac, you can run first a docker container with an open port on 8000:
docker run -it --rm --name ioid-sdk -p 8000:8000 -v $(pwd):/workspace -w /workspace node:20 bash
Then run the exectutable ./DeviceRegister.
Make sure to register your device on IoTeX testnet here.
cargo run generate-onchain-verifier-contract
This will generate the solidity contract and the calldata for the onchain verifier in ./hardhat/contracts/.
cd hardhat
npx hardhat run scripts/deploy-onchain-verifier.js --network iotex_testnet
This will return the hash of the deployed contract.
- Modify
./scripts/deploy-rewards-demo.jsand replace theOnchainVerifieraddress with the hash of the deployed contract.
const contract = await RewardDistributor.deploy(
"0xAD5f0101B94F581979AA22F123b7efd9501BfeB3", // OnchainVerifier contract
"0x0A7e595C7889dF3652A19aF52C18377bF17e027D", // ioID Registry
"0x45Ce3E6f526e597628c73B731a3e9Af7Fc32f5b7" // ioID Contract
);- Deploy the rewards contract
npx hardhat run scripts/deploy-rewards-demo.js --network iotex_testnet
This will return the hash of the deployed contract.
This is necessary since it is the rewards contract that will pay the reward.
ioctl contract invoke bytecode 0x389daDF8A8A9C800B2d6212A28283f58FF1D43fB "" 2
cd ..
- Change the addresses of the deployed contracts in
./src/constants.rs.
const NOVA_DECIDER_CONTRACT_ADDRESS = "0xAD5f0101B94F581979AA22F123b7efd9501BfeB3";
const REWARD_DISTRIBUTOR_CONTRACT_ADDRESS = "0xAD5f0101B94F581979AA22F123b7efd9501BfeB3";- Run the demo
cargo run
This will:
- generate a local proof of location
- compress the proof (locally but can be done with NovaNet)
- sign the compressed proof with the device's private key
- verify the proof onchain and reward the owner of the device
- print the transaction information of the rewards contract. You can check the transaction on IoTeX explorer. https://testnet.iotexscan.io/