From 42959c6f18b32c9c2ae27a018520858154374fb7 Mon Sep 17 00:00:00 2001 From: Jayant Krishnamurthy Date: Tue, 17 Oct 2023 12:53:42 -0700 Subject: [PATCH] pr comments --- .../contracts/random/PythRandomState.sol | 3 --- .../contracts/forge-test/PythRandom.t.sol | 19 +++++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/target_chains/ethereum/contracts/contracts/random/PythRandomState.sol b/target_chains/ethereum/contracts/contracts/random/PythRandomState.sol index 74ed9a68a..0ff407b4c 100644 --- a/target_chains/ethereum/contracts/contracts/random/PythRandomState.sol +++ b/target_chains/ethereum/contracts/contracts/random/PythRandomState.sol @@ -26,7 +26,6 @@ contract PythRandomStructs { // The contract maintains the invariant that sequenceNumber <= endSequenceNumber. // If sequenceNumber == endSequenceNumber, the provider must rotate their commitment to add additional random values. uint64 endSequenceNumber; - // The sequence number that will be assigned to the next inbound user request. uint64 sequenceNumber; // The current commitment represents an index/value in the provider's hash chain. @@ -37,10 +36,8 @@ contract PythRandomStructs { // are revealed on-chain. bytes32 currentCommitment; uint64 currentCommitmentSequenceNumber; - } - // TODO: add block number? struct Request { address provider; uint64 sequenceNumber; diff --git a/target_chains/ethereum/contracts/forge-test/PythRandom.t.sol b/target_chains/ethereum/contracts/forge-test/PythRandom.t.sol index ceaf6f571..c8e7c513c 100644 --- a/target_chains/ethereum/contracts/forge-test/PythRandom.t.sol +++ b/target_chains/ethereum/contracts/forge-test/PythRandom.t.sol @@ -14,7 +14,8 @@ import "./utils/RandTestUtils.t.sol"; import "../contracts/random/PythRandom.sol"; // TODO -// - what's the impact of # of in-flight requests on gas usage? +// - what's the impact of # of in-flight requests on gas usage? More requests => more hashes to +// verify the provider's value. // - fuzz test? contract PythRandomTest is Test, RandTestUtils { PythRandom public random; @@ -184,13 +185,19 @@ contract PythRandomTest is Test, RandTestUtils { PythRandomStructs.ProviderInfo memory info1 = random.getProviderInfo( provider1 ); - assert(info1.originalCommitmentSequenceNumber <= info1.currentCommitmentSequenceNumber); + assert( + info1.originalCommitmentSequenceNumber <= + info1.currentCommitmentSequenceNumber + ); assert(info1.currentCommitmentSequenceNumber < info1.sequenceNumber); assert(info1.sequenceNumber <= info1.endSequenceNumber); PythRandomStructs.ProviderInfo memory info2 = random.getProviderInfo( provider2 ); - assert(info2.originalCommitmentSequenceNumber <= info2.currentCommitmentSequenceNumber); + assert( + info2.originalCommitmentSequenceNumber <= + info2.currentCommitmentSequenceNumber + ); assert(info2.sequenceNumber > info2.currentCommitmentSequenceNumber); assert(info2.sequenceNumber <= info2.endSequenceNumber); } @@ -327,9 +334,13 @@ contract PythRandomTest is Test, RandTestUtils { provider1FeeInWei, newHashChain[0], bytes32(keccak256(abi.encodePacked(uint256(0x0100)))), - newHashChainOffset + 10 + 10 ); assertInvariants(); + PythRandomStructs.ProviderInfo memory info1 = random.getProviderInfo( + provider1 + ); + assertEq(info1.endSequenceNumber, newHashChainOffset + 10); uint64 sequenceNumber3 = request(user2, provider1, 42, false); // Rotating the provider key uses a sequence number