From 6eab9fee9a85eba460aec0b5703cff3cd90caece Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 17 Jan 2023 08:37:59 +0100 Subject: [PATCH] [marketplace] remove wrappers around proof functions No longer required; slot state is checked in Proofs.sol --- contracts/Marketplace.sol | 25 ------------------------- contracts/Proofs.sol | 30 +++++++++++++++--------------- contracts/TestProofs.sol | 16 ---------------- 3 files changed, 15 insertions(+), 56 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 97e391d..10c9eb5 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -249,31 +249,6 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { } } - function isProofRequired(SlotId slotId) public view returns (bool) { - if (slotState(slotId) != SlotState.Filled) { - return false; - } - return _isProofRequired(slotId); - } - - function willProofBeRequired(SlotId slotId) public view returns (bool) { - if (slotState(slotId) != SlotState.Filled) { - return false; - } - return _willProofBeRequired(slotId); - } - - function getChallenge(SlotId slotId) public view returns (bytes32) { - if (slotState(slotId) != SlotState.Filled) { - return bytes32(0); - } - return _getChallenge(slotId); - } - - function getPointer(SlotId slotId) public view returns (uint8) { - return _getPointer(slotId); - } - function _price( uint64 numSlots, uint256 duration, diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 9c4cd16..0c48b96 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -35,7 +35,7 @@ abstract contract Proofs is Periods { probabilities[id] = probability; } - function _getPointer( + function getPointer( SlotId id, Period proofPeriod ) internal view returns (uint8) { @@ -46,25 +46,25 @@ abstract contract Proofs is Periods { return uint8(pointer); } - function _getPointer(SlotId id) internal view returns (uint8) { - return _getPointer(id, blockPeriod()); + function getPointer(SlotId id) public view returns (uint8) { + return getPointer(id, blockPeriod()); } - function _getChallenge(uint8 pointer) internal view returns (bytes32) { + function getChallenge(uint8 pointer) internal view returns (bytes32) { bytes32 hash = blockhash(block.number - 1 - pointer); assert(uint256(hash) != 0); return keccak256(abi.encode(hash)); } - function _getChallenge( + function getChallenge( SlotId id, Period proofPeriod ) internal view returns (bytes32) { - return _getChallenge(_getPointer(id, proofPeriod)); + return getChallenge(getPointer(id, proofPeriod)); } - function _getChallenge(SlotId id) internal view returns (bytes32) { - return _getChallenge(id, blockPeriod()); + function getChallenge(SlotId id) public view returns (bytes32) { + return getChallenge(id, blockPeriod()); } function _getProofRequirement( @@ -76,13 +76,13 @@ abstract contract Proofs is Periods { if (state != SlotState.Filled || !isAfter(proofPeriod, start)) { return (false, 0); } - pointer = _getPointer(id, proofPeriod); - bytes32 challenge = _getChallenge(pointer); + pointer = getPointer(id, proofPeriod); + bytes32 challenge = getChallenge(pointer); uint256 probability = (probabilities[id] * (256 - downtime)) / 256; isRequired = uint256(challenge) % probability == 0; } - function _isProofRequired( + function isProofRequired( SlotId id, Period proofPeriod ) internal view returns (bool) { @@ -92,11 +92,11 @@ abstract contract Proofs is Periods { return isRequired && pointer >= downtime; } - function _isProofRequired(SlotId id) internal view returns (bool) { - return _isProofRequired(id, blockPeriod()); + function isProofRequired(SlotId id) public view returns (bool) { + return isProofRequired(id, blockPeriod()); } - function _willProofBeRequired(SlotId id) internal view returns (bool) { + function willProofBeRequired(SlotId id) public view returns (bool) { bool isRequired; uint8 pointer; (isRequired, pointer) = _getProofRequirement(id, blockPeriod()); @@ -115,7 +115,7 @@ abstract contract Proofs is Periods { require(periodEnd < block.timestamp, "Period has not ended yet"); require(block.timestamp < periodEnd + proofTimeout, "Validation timed out"); require(!received[id][missedPeriod], "Proof was submitted, not missing"); - require(_isProofRequired(id, missedPeriod), "Proof was not required"); + require(isProofRequired(id, missedPeriod), "Proof was not required"); require(!missing[id][missedPeriod], "Proof already marked as missing"); missing[id][missedPeriod] = true; missed[id] += 1; diff --git a/contracts/TestProofs.sol b/contracts/TestProofs.sol index 356073b..e4f1f4c 100644 --- a/contracts/TestProofs.sol +++ b/contracts/TestProofs.sol @@ -26,22 +26,6 @@ contract TestProofs is Proofs { _startRequiringProofs(slot, _probability); } - function isProofRequired(SlotId id) public view returns (bool) { - return _isProofRequired(id); - } - - function willProofBeRequired(SlotId id) public view returns (bool) { - return _willProofBeRequired(id); - } - - function getChallenge(SlotId id) public view returns (bytes32) { - return _getChallenge(id); - } - - function getPointer(SlotId id) public view returns (uint8) { - return _getPointer(id); - } - function markProofAsMissing(SlotId id, Period _period) public { _markProofAsMissing(id, _period); }