From 23a4b848161e9789a8ca761e67dc005629332168 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 14 Oct 2021 14:01:28 +0200 Subject: [PATCH] Add proof period and timeout to request for storage --- contracts/StorageContract.sol | 8 +++++--- test/StorageContract.test.js | 7 +++++-- test/marketplace.js | 6 +++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/contracts/StorageContract.sol b/contracts/StorageContract.sol index 486c8e7..fef4ee4 100644 --- a/contracts/StorageContract.sol +++ b/contracts/StorageContract.sol @@ -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 )); } diff --git a/test/StorageContract.test.js b/test/StorageContract.test.js index 7fc5d59..aff1179 100644 --- a/test/StorageContract.test.js +++ b/test/StorageContract.test.js @@ -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, diff --git a/test/marketplace.js b/test/marketplace.js index 477e882..5a2e078 100644 --- a/test/marketplace.js +++ b/test/marketplace.js @@ -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] ) }