Mini Pine Rattlesnake
Medium
A lack of consistent type declaration, specifically the use of uint
instead of uint256
, has been identified within the loan processing functions in the PredictDotLoan
contract. This typographical inconsistency can lead to incorrect calculations when handling substantial financial transactions.
The vulnerability arises from using an inconsistent type definition for a key variable within critical financial computation processes, leading to inaccurate results.
1555: function _getConditionId(address oracle, bytes32 questionId, uint outcomeSlotCount) private pure returns (bytes32) {
1556:@=> return keccak256(abi.encodePacked(oracle, questionId, outcomeSlotCount));
1557: }
---
1562: function _getPositionId(IERC20 collateralToken, bytes32 collectionId) private pure returns (uint) {
1563:@=> return uint(keccak256(abi.encodePacked(collateralToken, collectionId)));
1564: }
1565: }
This issue occurs because Solidity defaults uint and it may not always explicitly match platform-specific data width without careful alignment with overarching computing logic architecture based on size assumptions.
- https://github.com/sherlock-audit/2024-09-predict-fun/blob/main/predict-dot-loan/contracts/PredictDotLoan.sol#L1556
- https://github.com/sherlock-audit/2024-09-predict-fun/blob/main/predict-dot-loan/contracts/PredictDotLoan.sol#L1563
- A borrower initiates a request for a specific loan amount within the contract using default typing (
uint
). - Due to type inconsistency, the actual processed amount during computations diverges from expectations.
- The lender ends up transacting an incorrect value without noticing any discrepancy until reconciliation efforts uncover inconsistencies much later on.
- Incorrect values derive reduction precision result facilitating losses/provisions shortcuts.
- Incorrect loan disbursement calculations can result in users receiving more or less than they should.
This is a derivative contract of PredictDotLoan.t.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;
import {PredictDotLoan_Test} from "./PredictDotLoan.t.sol";
import {IPredictDotLoan} from "../../contracts/interfaces/IPredictDotLoan.sol";
import {MockERC20} from "../mock/MockERC20.sol";
contract PredictDotLoan_InconsistentTypes_Test is PredictDotLoan_Test {
function test_InconsistentTypes_Exploit() public {
// Setup initial state
setUp();
// Generate a loan offer with inconsistent data types
IPredictDotLoan.Proposal memory proposal = _generateLoanOffer(IPredictDotLoan.QuestionType.Binary);
// Intentionally use uint instead of uint256 to simulate inconsistency
uint incorrectLoanAmount = proposal.loanAmount / 2; // Incorrect calculation due to type inconsistency
// Attempt to accept the loan offer with the incorrect loan amount
vm.prank(borrower);
predictDotLoan.acceptLoanOffer(proposal, incorrectLoanAmount);
// Check if the loan amount was incorrectly processed
uint256 actualLoanAmount = mockERC20.balanceOf(borrower);
// The expected incorrect loan amount due to inconsistency
uint256 expectedIncorrectLoanAmount = incorrectLoanAmount;
// Assert that the incorrect loan amount matches the expected incorrect result
assertEq(actualLoanAmount, expectedIncorrectLoanAmount, "Inconsistent types led to incorrect loan amount calculation");
// If the test passes, it means the inconsistency was successfully demonstrated
emit log("PASS: Inconsistent types led to incorrect loan amount calculation");
}
}
├─ emit log(val: "PASS: Inconsistent types led to incorrect loan amount calculation")
Replace all of uint
with uint256
, ensuring explicit and consistent data handling across smart contracts processing transactions.