Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rename totalRequestCount to nextRequestNonce #64

Open
wants to merge 3 commits into
base: fix/oz-audit
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ contract Oracle is IOracle, OracleAccessController {
mapping(bytes32 _requestId => mapping(address _user => bool _isParticipant)) public isParticipant;

/// @inheritdoc IOracle
uint256 public totalRequestCount;
uint256 public nextRequestNonce;

/**
* @notice The list of the response ids for each request
Expand All @@ -72,15 +72,15 @@ contract Oracle is IOracle, OracleAccessController {

/// @inheritdoc IOracle
function listRequestIds(uint256 _startFrom, uint256 _batchSize) external view returns (bytes32[] memory _list) {
uint256 _totalRequestsCount = totalRequestCount;
uint256 _nextRequestNonce = nextRequestNonce;

// If trying to collect non-existent ids only, return empty array
if (_startFrom > _totalRequestsCount) {
if (_startFrom >= _nextRequestNonce) {
return _list;
}

if (_batchSize > _totalRequestsCount - _startFrom) {
_batchSize = _totalRequestsCount - _startFrom;
if (_batchSize > _nextRequestNonce - _startFrom) {
_batchSize = _nextRequestNonce - _startFrom;
}

_list = new bytes32[](_batchSize);
Expand Down Expand Up @@ -443,7 +443,8 @@ contract Oracle is IOracle, OracleAccessController {
hasAccess(_request.accessModule, OracleTypehash.CREATE_TYPEHASH, abi.encode(_request), _accessControl)
returns (bytes32 _requestId)
{
uint256 _requestNonce = totalRequestCount++;
// we assign the next request nonce, then increment it by 1
uint256 _requestNonce = nextRequestNonce++;

if (_request.nonce == 0) _request.nonce = uint96(_requestNonce);

Expand Down
6 changes: 3 additions & 3 deletions solidity/interfaces/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ interface IOracle is IOracleAccessController {
function isParticipant(bytes32 _requestId, address _user) external view returns (bool _isParticipant);

/**
* @notice Returns the total number of requests stored in the oracle
* @notice Returns the next request nonce.
*
* @return _count The total number of requests
* @return _nextNonce The next request nonce
*/
function totalRequestCount() external view returns (uint256 _count);
function nextRequestNonce() external view returns (uint256 _nextNonce);

/**
* @notice Returns the list of request IDs
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/ResponseDispute.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract Integration_ResponseDispute is IntegrationBase {
_expectedDeadline = block.timestamp + BLOCK_TIME * 600;
_responseData = abi.encode('response');

mockRequest.nonce = uint96(oracle.totalRequestCount());
mockRequest.nonce = uint96(oracle.nextRequestNonce());

mockAccessControl.user = requester;
_requestId = oracle.createRequest(mockRequest, _ipfsHash, mockAccessControl);
Expand Down
2 changes: 1 addition & 1 deletion solidity/test/integration/ResponseProposal.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract Integration_ResponseProposal is IntegrationBase {
function setUp() public override {
super.setUp();

mockRequest.nonce = uint96(oracle.totalRequestCount());
mockRequest.nonce = uint96(oracle.nextRequestNonce());

address _badRequester = makeAddr('badRequester');
mockAccessControl.user = _badRequester;
Expand Down
26 changes: 13 additions & 13 deletions solidity/test/unit/Oracle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ contract MockOracle is Oracle {
disputeCreatedAt[_disputeId] = _disputeCreatedAt;
}

function mock_setTotalRequestCount(uint256 _totalRequestCount) external {
totalRequestCount = _totalRequestCount;
function mock_setNextRequestNonce(uint256 _nextRequestNonce) external {
nextRequestNonce = _nextRequestNonce;
}

function mock_addResponseId(bytes32 _requestId, bytes32 _responseId) external {
Expand Down Expand Up @@ -156,7 +156,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {
bytes calldata _resolutionData,
bytes calldata _finalityData
) public setResolutionAndFinality(_useResolutionAndFinality) happyPath {
uint256 _initialNonce = oracle.totalRequestCount();
uint256 _initialNonce = oracle.nextRequestNonce();

// Create the request
mockRequest.requestModuleData = _requestData;
Expand All @@ -165,7 +165,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {
mockRequest.resolutionModuleData = _resolutionData;
mockRequest.finalityModuleData = _finalityData;
mockRequest.requester = requester;
mockRequest.nonce = uint96(oracle.totalRequestCount());
mockRequest.nonce = uint96(oracle.nextRequestNonce());

// Compute the associated request id
bytes32 _theoreticalRequestId = _getId(mockRequest);
Expand Down Expand Up @@ -200,7 +200,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {
assertEq(_requestId, _theoreticalRequestId);

// Check: nonce incremented?
assertEq(oracle.totalRequestCount(), _initialNonce + 1);
assertEq(oracle.nextRequestNonce(), _initialNonce + 1);
}

/**
Expand Down Expand Up @@ -235,7 +235,7 @@ contract Oracle_Unit_CreateRequest is BaseTest {
* @notice Check that creating a request with a nonce that already exists reverts
*/
function test_createRequest_revertsIfInvalidNonce(uint256 _nonce) public happyPath {
vm.assume(_nonce != oracle.totalRequestCount());
vm.assume(_nonce != oracle.nextRequestNonce());

// Set the nonce
mockRequest.nonce = uint96(_nonce);
Expand Down Expand Up @@ -273,7 +273,7 @@ contract Oracle_Unit_CreateRequests is BaseTest {
bytes calldata _responseData,
bytes calldata _disputeData
) public {
uint256 _initialNonce = oracle.totalRequestCount();
uint256 _initialNonce = oracle.nextRequestNonce();
uint256 _requestsAmount = 5;
IOracle.Request[] memory _requests = new IOracle.Request[](_requestsAmount);
bytes32[] memory _precalculatedIds = new bytes32[](_requestsAmount);
Expand All @@ -290,7 +290,7 @@ contract Oracle_Unit_CreateRequests is BaseTest {
mockRequest.responseModuleData = _responseData;
mockRequest.disputeModuleData = _disputeData;
mockRequest.requester = requester;
mockRequest.nonce = uint96(oracle.totalRequestCount() + _i);
mockRequest.nonce = uint96(oracle.nextRequestNonce() + _i);

bytes32 _theoreticalRequestId = _getId(mockRequest);
_requests[_i] = mockRequest;
Expand Down Expand Up @@ -329,7 +329,7 @@ contract Oracle_Unit_CreateRequests is BaseTest {
assertEq(oracle.nonceToRequestId(_requests[_i].nonce), _requestsIds[_i]);
}

uint256 _newNonce = oracle.totalRequestCount();
uint256 _newNonce = oracle.nextRequestNonce();
assertEq(_newNonce, _initialNonce + _requestsAmount);
}

Expand All @@ -341,7 +341,7 @@ contract Oracle_Unit_CreateRequests is BaseTest {
bytes calldata _responseData,
bytes calldata _disputeData
) public {
uint256 _initialNonce = oracle.totalRequestCount();
uint256 _initialNonce = oracle.nextRequestNonce();
uint256 _requestsAmount = 5;
IOracle.Request[] memory _requests = new IOracle.Request[](_requestsAmount);
bytes32[] memory _precalculatedIds = new bytes32[](_requestsAmount);
Expand Down Expand Up @@ -369,7 +369,7 @@ contract Oracle_Unit_CreateRequests is BaseTest {
oracle.mock_setAccessModuleApproved(requester, address(accessModule), true);
oracle.createRequests(_requests, _ipfsHashes, _accessControls);

uint256 _newNonce = oracle.totalRequestCount();
uint256 _newNonce = oracle.nextRequestNonce();
assertEq(_newNonce, _initialNonce + _requestsAmount);
}
}
Expand All @@ -391,7 +391,7 @@ contract Oracle_Unit_ListRequestIds is BaseTest {
oracle.mock_setRequestId(_i, _requestId);
}

oracle.mock_setTotalRequestCount(_numberOfRequests);
oracle.mock_setNextRequestNonce(_numberOfRequests);

// Test: fetching the requests
bytes32[] memory _requestsIds = oracle.listRequestIds(0, _numberOfRequests);
Expand Down Expand Up @@ -421,7 +421,7 @@ contract Oracle_Unit_ListRequestIds is BaseTest {
oracle.mock_setRequestId(_i, _requestId);
}

oracle.mock_setTotalRequestCount(_numberOfRequests);
oracle.mock_setNextRequestNonce(_numberOfRequests);

// Test: fetching 1 extra request
bytes32[] memory _requestsIds = oracle.listRequestIds(0, _numberOfRequests + 1);
Expand Down
Loading