Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jayantk committed Oct 17, 2023
1 parent 62c21ec commit 42959c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -37,10 +36,8 @@ contract PythRandomStructs {
// are revealed on-chain.
bytes32 currentCommitment;
uint64 currentCommitmentSequenceNumber;

}

// TODO: add block number?
struct Request {
address provider;
uint64 sequenceNumber;
Expand Down
19 changes: 15 additions & 4 deletions target_chains/ethereum/contracts/forge-test/PythRandom.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 42959c6

Please sign in to comment.