31524 - [SC - High] Rounding down in getClaimableFlux leads to less...
Previous31523 - [SC - Low] USDT Approval will cause function failureNext31526 - [SC - Critical] A user is able to claim more bribes than they h...
Last updated
Was this helpful?
Was this helpful?
function getClaimableFlux(uint256 _amount, address _nft) public view returns (uint256 claimableFlux) {
uint256 bpt = calculateBPT(_amount);
uint256 veMul = IVotingEscrow(veALCX).MULTIPLIER();
uint256 veMax = IVotingEscrow(veALCX).MAXTIME();
uint256 fluxPerVe = IVotingEscrow(veALCX).fluxPerVeALCX();
uint256 fluxMul = IVotingEscrow(veALCX).fluxMultiplier();
// Amount of flux earned in 1 yr from _amount assuming it was deposited for maxtime
- claimableFlux = (((bpt * veMul) / veMax) * veMax * (fluxPerVe + BPS)) / BPS / fluxMul;
+ claimableFlux_modified = (bpt * veMul * veMax * (fluxPerVe + BPS)) / (BPS * fluxMul * veMax); // all division after multiplication
// Claimable flux for alchemechNFT is different than patronNFT
if (_nft == alchemechNFT) {
claimableFlux = (claimableFlux * alchemechMultiplier) / BPS;
}
} // forge t --mt test_rewardFlux -vv
function test_rewardFlux() external view {
uint256 bpt = 1000e18 * 40; // 1000 tokens passed as param to calculateBPT() of FluxToken
uint256 BPS = 10_000; // value taken from VotingEscrow contract
uint256 veMul = 2; // value taken from VotingEscrow contract
uint256 veMax = 365 days; // value taken from VotingEscrow contract
uint256 fluxPerVe = 5000;// value taken from VotingEscrow contract
uint256 fluxMul = 4;// value taken from VotingEscrow contract
uint256 alchemechNFT = 5;// value taken from VotingEscrow contract
uint256 _nft = 5; // value assumed for VotingEscrow contract
// Amount of flux earned in 1 yr from _amount assuming it was deposited for maxtime
uint256 claimableFlux = (((bpt * veMul) / veMax) * veMax * (fluxPerVe + BPS)) / BPS / fluxMul;
console.log("claimableFlux: %e", claimableFlux); // value on multiply result of division
uint256 claimableFlux_modified = (bpt * veMul * veMax * (fluxPerVe + BPS)) / (BPS * fluxMul * veMax); // all division after multiplication
console.log("claimableFlux_modified: %e", claimableFlux_modified); // value when all division is after multiply
if (_nft == alchemechNFT) {
claimableFlux = (claimableFlux * alchemechNFT) / BPS;
console.log("Nft claimableFlux: %e", claimableFlux); // resultant value on default code
claimableFlux_modified = (claimableFlux_modified * alchemechNFT) / BPS;
console.log("Nft claimableFlux_modified: %e", claimableFlux_modified); // resultant value on modified code
}
} [PASS] test_rewardFlux() (gas: 7126)
Logs:
claimableFlux: 2.9999999999999989116e22
claimableFlux_modified: 3e22
Nft claimableFlux: 1.4999999999999994558e19
Nft claimableFlux_modified: 1.5e19
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.75ms (278.70µs CPU time)
Ran 1 test suite in 147.11ms (1.75ms CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)