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

Can't retrieve all data with getMarketInfo #14

Open
code423n4 opened this issue Aug 21, 2021 · 2 comments
Open

Can't retrieve all data with getMarketInfo #14

code423n4 opened this issue Aug 21, 2021 · 2 comments
Labels
1 (Low Risk) bug Something isn't working Resolved Used when a fix has been implemented. sponsor confirmed

Comments

@code423n4
Copy link
Contributor

Handle

gpersoon

Vulnerability details

Impact

The function getMarketInfo of RCFactory only can give results back in the range 0...marketInfoResults
Supplying _skipResults doesn't help, it then just skips the first _skipResults records.

Assume marketInfoResults == 10 and _skipResults == 20:
Then no result will be given back because "_resultNumber < marketInfoResults" will never allow _resultNumber to be bigger than 10

Note: this is low risk because getMarketInfo is a backup function (although you maybe want the backup to function as expected)

Proof of Concept

// https://github.com/code-423n4/2021-08-realitycards/blob/main/contracts/RCFactory.sol#L227
function getMarketInfo( IRCMarket.Mode _mode, uint256 _state, uint256 _skipResults ) external view
returns ( address[] memory, string[] memory, string[] memory, uint256[] memory ) {
..
uint256 _resultNumber = 0;
..
while (_resultNumber < marketInfoResults && _marketIndex > 1) {
...
if (_resultNumber < _skipResults) {
_resultNumber++;
} else {
_marketAddresses[_resultNumber] = _market; // will never reach this part if _skipResults >= marketInfoResults
....
_resultNumber++;
}
}
}
return (_marketAddresses, _ipfsHashes, _slugs, _potSizes);
}

Tools Used

Recommended Mitigation Steps

Update the code to something like the following:

uint idx;
while (idx < marketInfoResults && _marketIndex > 1) {
_marketIndex--;
address _market = marketAddresses[_mode][_marketIndex];
if (IRCMarket(_market).state() == IRCMarket.States(_state)) {
if (_resultNumber < _skipResults) {
_resultNumber++;
} else {
_marketAddresses[idx] = _market;
_ipfsHashes[idx] = ipfsHash[_market];
_slugs[idx] = addressToSlug[_market];
_potSizes[idx] = IRCMarket(_market).totalRentCollected();
idx++;
}
}
}

@code423n4 code423n4 added 1 (Low Risk) bug Something isn't working labels Aug 21, 2021
code423n4 added a commit that referenced this issue Aug 21, 2021
@Splidge
Copy link
Collaborator

Splidge commented Aug 24, 2021

Yep, this was a last minute untested addition.
In implementing your recommended fix I hit "Stack too deep" problems, so have split the function in two with one being internal. Firstly getMarketInfo will get the market addresses required and then _getMarketInfo will get the additional info required. This change has allowed me to remove the separate marketResults variable and pass the required number of results directly to getMarketInfo.

@Splidge
Copy link
Collaborator

Splidge commented Sep 7, 2021

Fixed here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) bug Something isn't working Resolved Used when a fix has been implemented. sponsor confirmed
Projects
None yet
Development

No branches or pull requests

2 participants