Summary
veRAACToken.sol::getLockedBalance() and veRAACToken.sol::getLockEndTime() are using the locks mapping to return the values of the lockedBalance and it's endTime, but the locks mapping is never been set/used, resulting in always returning 0.
Vulnerability Details
Users that make call to this functions will get a 0 value in return, instead of the real values.
The locks mapping is never updated or set to any value which results in that this two functions to always return 0.
* @notice Gets the amount of RAAC tokens locked by an account
* @dev Returns the raw locked token amount without time-weighting
* @param account The address to check
* @return The amount of RAAC tokens locked by the account
*/
function getLockedBalance(address account) external view returns (uint256) {
return locks[account].amount;
}
* @notice Gets the lock end time for an account
* @dev Returns the timestamp when the lock expires
* @param account The address to check
* @return The unix timestamp when the lock expires
*/
function getLockEndTime(address account) external view returns (uint256) {
return locks[account].end;
}
Impact
Users who call this function will always receive 0, leading to misleading information about their locked tokens or the lock end time.
POC with instructions
How to run the test:
Add the test inside test/unit/core/tokens/veRAACToken.test.js
Run this to execute the test: npx hardhat test --grep "LOCK POCS"
describe("LOCK POCS", () => {
it("should not always return 0 when calling getLockedBalance() and getLockEndTime(), but they do", async () => {
const amount = ethers.parseEther("1000");
const duration = 365 * 24 * 3600;
await veRAACToken.connect(users[0]).lock(amount, duration);
expect(await veRAACToken.connect(users[0]).getLockedBalance(users[0])).to.be.equal(0);
expect(await veRAACToken.connect(users[0]).getLockEndTime(users[0])).to.be.equal(0);
const lockPosition = await veRAACToken.connect(users[0]).getLockPosition(users[0]);
expect(lockPosition.amount).to.be.gt(0);
expect(lockPosition.end).to.be.gt(0);
expect(lockPosition.power).to.be.gt(0);
});
});
Tools Used
Manual
Recommendations
function getLockedBalance(address account) external view returns (uint256) {
- return locks[account].amount;
+ return _lockState.locks[account].amount;
}
function getLockEndTime(address account) external view returns (uint256) {
- return locks[account].end;
+ return _lockState.locks[account].end;
}