pragma solidity >=0.8.2 <0.9.0;
contract retwi_rng {
uint256 number;
event retwi_number(uint256 indexed num);
function input(uint256 num) public {
emit retwi_number(num);
}
function retrieve() public view returns (uint256) {
return number;
}
}
export function handleEvent(esig: Uint8Array, topic1: Uint8Array, topic2: Uint8Array, topic3: Uint8Array, data: Uint8Array): Uint8Array {
// Get on-chain input data from topic1 of event.
var input = changetype<Bytes>(topic1);
input = input.slice(32-8,32);
var num = input.toU64();
// Make raffle output random!
let year = 23;
let month = 6;
let day = 19;
let raffle = num;
for (let i = 0; i < 4; i++) {
raffle = (raffle * year - month) % day;
}
// Output raffle result as state
let state = Bytes.new(32);
state.fromU64(raffle);
return state as Uint8Array;
}
- Raffle smart contract deployed: https://etherscan.io/address/0x65747849e7033cd1da6bf5aeb753460f61743b18
- Transaction emitted event: https://etherscan.io/tx/0x5c6d0acadf750dc7d6a1c7f70c343d9c2b41b541ae9341ff192f5fa1fa28832c
- WASM image setup: https://zkwasm-explorer.delphinuslab.com/task/649007dff0e3eee93f5fa123
- ZK proof generation: https://zkwasm-explorer.delphinuslab.com/task/649008e4f0e3eee93f5fa1dd
- Verifier smart contract deployment: https://zkwasm-explorer.delphinuslab.com/task/64900e32f0e3eee93f5fa495
- Verifier smart contract deployed: https://sepolia.etherscan.io/address/0x1945b02203ca8563be237ad3e8a86082e7a46c02