Add proof period and timeout to request for storage

This commit is contained in:
Mark Spanbroek 2021-10-14 14:01:28 +02:00
parent cbf34df013
commit 23a4b84816
3 changed files with 13 additions and 8 deletions

View File

@ -21,7 +21,7 @@ contract StorageContract {
bytes memory requestSignature,
bytes memory bidSignature)
{
bytes32 requestHash = hashRequest(_duration, _size);
bytes32 requestHash = hashRequest(_duration, _size, _proofPeriod, _proofTimeout);
bytes32 bidHash = hashBid(requestHash, _price);
checkSignature(requestSignature, requestHash, msg.sender);
checkSignature(bidSignature, bidHash, _host);
@ -36,14 +36,16 @@ contract StorageContract {
}
// Creates hash for a storage request that can be used to check its signature.
function hashRequest(uint _duration, uint _size)
function hashRequest(uint _duration, uint _size, uint _proofPeriod, uint _proofTimeout)
internal pure
returns (bytes32)
{
return keccak256(abi.encodePacked(
"[dagger.request.v1]",
_duration,
_size
_size,
_proofPeriod,
_proofTimeout
));
}

View File

@ -18,7 +18,7 @@ describe("Storage Contract", function () {
beforeEach(async function () {
[client, host] = await ethers.getSigners()
StorageContract = await ethers.getContractFactory("StorageContract")
requestHash = hashRequest(duration, size)
requestHash = hashRequest(duration, size, proofPeriod, proofTimeout)
bidHash = hashBid(requestHash, price)
})
@ -63,7 +63,8 @@ describe("Storage Contract", function () {
})
it("cannot be created when client signature is invalid", async function () {
let invalidSignature = await sign(client, hashRequest(duration + 1, size))
let invalidHash = hashRequest(duration + 1, size, proofPeriod, proofTimeout)
let invalidSignature = await sign(client, invalidHash)
await expect(StorageContract.deploy(
duration,
size,
@ -92,6 +93,8 @@ describe("Storage Contract", function () {
it("cannot be created when proof timeout is too large", async function () {
let invalidTimeout = 129 // max proof timeout is 128 blocks
requestHash = hashRequest(duration, size, proofPeriod, invalidTimeout)
bidHash = hashBid(requestHash, price)
await expect(StorageContract.deploy(
duration,
size,

View File

@ -1,9 +1,9 @@
const { ethers } = require("hardhat")
function hashRequest(duration, size) {
function hashRequest(duration, size, proofPeriod, proofTimeout) {
return ethers.utils.solidityKeccak256(
["string", "uint", "uint"],
["[dagger.request.v1]", duration, size]
["string", "uint", "uint", "uint", "uint"],
["[dagger.request.v1]", duration, size, proofPeriod, proofTimeout]
)
}