Add (dummy) proof submission

This commit is contained in:
Mark Spanbroek 2021-10-18 14:55:59 +02:00
parent 01e18ee494
commit 71efdd36c7
2 changed files with 57 additions and 1 deletions

View File

@ -13,6 +13,8 @@ contract StorageContract {
uint public immutable proofTimeout; // proof has to be submitted before this
uint public immutable proofMarker; // indicates when a proof is required
mapping(uint => bool) proofReceived; // whether proof for a block was received
constructor(uint _duration,
uint _size,
bytes32 _contentHash,
@ -101,4 +103,15 @@ contract StorageContract {
bytes32 hash = blockhash(blocknumber);
return hash != 0 && uint(hash) % proofPeriod == proofMarker;
}
function submitProof(uint blocknumber, bool proof) public {
require(proof, "Invalid proof"); // TODO: replace bool by actual proof
require(isProofRequired(blocknumber), "No proof required for this block");
require(
block.number < blocknumber + proofTimeout,
"Proof not allowed after timeout"
);
require(!proofReceived[blocknumber], "Proof already submitted");
proofReceived[blocknumber] = true;
}
}

View File

@ -186,13 +186,56 @@ describe("Storage Contract", function () {
expect(await contract.isProofRequired(blocknumber)).to.be.false
})
it("submits a correct proof", async function () {
await mineUntilProofIsRequired()
let blocknumber = await minedBlockNumber()
await contract.submitProof(blocknumber, true)
})
it("fails proof submission when proof is incorrect", async function () {
await mineUntilProofIsRequired()
let blocknumber = await minedBlockNumber()
await expect(
contract.submitProof(blocknumber, false)
).to.be.revertedWith("Invalid proof")
})
it("fails proof submission when proof was not required", async function () {
while (await contract.isProofRequired(await minedBlockNumber())) {
await mineBlock()
}
let blocknumber = await minedBlockNumber()
await expect(
contract.submitProof(blocknumber, true)
).to.be.revertedWith("No proof required")
})
it("fails proof submission when proof is too late", async function () {
await mineUntilProofIsRequired()
let blocknumber = await minedBlockNumber()
for (let i=0; i<proofTimeout; i++) {
mineBlock()
}
await expect(
contract.submitProof(blocknumber, true)
).to.be.revertedWith("Proof not allowed after timeout")
})
it("fails proof submission when already submitted", async function() {
await mineUntilProofIsRequired()
let blocknumber = await minedBlockNumber()
await contract.submitProof(blocknumber, true)
await expect(
contract.submitProof(blocknumber, true)
).to.be.revertedWith("Proof already submitted")
})
})
})
// TODO: implement checking of actual proofs of storage, instead of dummy bool
// TODO: payment on constructor
// TODO: contract start and timeout
// TODO: missed proofs
// TODO: successfull proofs
// TODO: only allow proofs after start of contract
// TODO: payout
// TODO: stake