mirror of
https://github.com/fluencelabs/lazy-snark
synced 2025-06-12 22:41:26 +00:00
initial contracts
This commit is contained in:
23
truffle/contracts/Migrations.sol
Normal file
23
truffle/contracts/Migrations.sol
Normal file
@ -0,0 +1,23 @@
|
||||
pragma solidity >=0.4.21 <0.6.0;
|
||||
|
||||
contract Migrations {
|
||||
address public owner;
|
||||
uint public last_completed_migration;
|
||||
|
||||
constructor() public {
|
||||
owner = msg.sender;
|
||||
}
|
||||
|
||||
modifier restricted() {
|
||||
if (msg.sender == owner) _;
|
||||
}
|
||||
|
||||
function setCompleted(uint completed) public restricted {
|
||||
last_completed_migration = completed;
|
||||
}
|
||||
|
||||
function upgrade(address new_address) public restricted {
|
||||
Migrations upgraded = Migrations(new_address);
|
||||
upgraded.setCompleted(last_completed_migration);
|
||||
}
|
||||
}
|
80
truffle/contracts/lazy.sol
Normal file
80
truffle/contracts/lazy.sol
Normal file
@ -0,0 +1,80 @@
|
||||
pragma solidity ^0.5.4;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
interface Structs {
|
||||
struct Data {
|
||||
uint x;
|
||||
}
|
||||
|
||||
struct Proof {
|
||||
uint x;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
contract Verifier is Structs {
|
||||
function isValid(Data calldata data, Proof calldata proof) external returns (bool);
|
||||
}
|
||||
|
||||
contract Lazy is Structs {
|
||||
event Submitted(address indexed sender, uint256 index, Task task);
|
||||
event Challenged(address indexed challenger, uint256 index);
|
||||
|
||||
|
||||
enum Status {UNCHECKED, VALID, INVALID, FINALIZED}
|
||||
struct Task {
|
||||
Data data;
|
||||
Proof proof;
|
||||
address payable submitter;
|
||||
uint96 timestamp;
|
||||
Status status;
|
||||
}
|
||||
|
||||
Task[] public tasks;
|
||||
|
||||
uint256 public stake;
|
||||
Verifier public verifier;
|
||||
|
||||
/// @dev This function submits data.
|
||||
/// @param data - public inptut for zkp
|
||||
/// @param proof - proof that verifies input
|
||||
function submit(Data calldata data, Proof calldata proof) external payable {
|
||||
require(msg.value == stake);
|
||||
|
||||
Task memory task = Task(data, proof, msg.sender, uint96(now), Status.UNCHECKED);
|
||||
uint index = tasks.push(task);
|
||||
|
||||
emit Submitted(msg.sender, index, task);
|
||||
}
|
||||
|
||||
/// @dev This function challenges a submission by calling the validation function.
|
||||
/// @param id The id of the submission to challenge.
|
||||
function challenge(uint id) external {
|
||||
Task storage task = tasks[id];
|
||||
require(now < task.timestamp + 1 weeks);
|
||||
require(task.status == Status.UNCHECKED);
|
||||
|
||||
if (verifier.isValid(task.data, task.proof)) {
|
||||
task.status = Status.VALID;
|
||||
task.submitter.transfer(stake);
|
||||
} else {
|
||||
task.status = Status.INVALID;
|
||||
msg.sender.transfer(stake);
|
||||
}
|
||||
|
||||
|
||||
// пруф не подходит, на это надо реагировать
|
||||
|
||||
emit Challenged(msg.sender, id);
|
||||
}
|
||||
|
||||
function finzalize(uint id) external {
|
||||
Task storage task = tasks[id];
|
||||
require(now > task.timestamp + 1 weeks);
|
||||
require(task.status == Status.UNCHECKED);
|
||||
|
||||
task.status = Status.FINALIZED;
|
||||
msg.sender.transfer(stake);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user