Skip to content

Commit f9af7eb

Browse files
committed
fix: round up when calculating curation fees and the protocol tax (OZ L-01)
1 parent 3882b35 commit f9af7eb

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

contracts/staking/Staking.sol

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,13 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
950950
bool isCurationEnabled = _curationPercentage > 0 && address(curation) != address(0);
951951

952952
if (isCurationEnabled && curation.isCurated(_subgraphDeploymentID)) {
953-
uint256 curationFees = uint256(_curationPercentage).mul(_tokens).div(MAX_PPM);
953+
// Calculate the tokens after curation fees first, and subtact that,
954+
// to prevent curation fees from rounding down to zero
955+
uint256 tokensAfterCurationFees = uint256(MAX_PPM)
956+
.sub(_curationPercentage)
957+
.mul(_tokens)
958+
.div(MAX_PPM);
959+
uint256 curationFees = _tokens.sub(tokensAfterCurationFees);
954960
if (curationFees > 0) {
955961
// Transfer and call collect()
956962
// This function transfer tokens to a trusted protocol contracts
@@ -976,7 +982,10 @@ abstract contract Staking is StakingV4Storage, GraphUpgradeable, IStakingBase, M
976982
uint256 _tokens,
977983
uint256 _percentage
978984
) private returns (uint256) {
979-
uint256 tax = uint256(_percentage).mul(_tokens).div(MAX_PPM);
985+
// Calculate tokens after tax first, and subtract that,
986+
// to prevent the tax from rounding down to zero
987+
uint256 tokensAfterTax = uint256(MAX_PPM).sub(_percentage).mul(_tokens).div(MAX_PPM);
988+
uint256 tax = _tokens.sub(tokensAfterTax);
980989
TokenUtils.burnTokens(_graphToken, tax); // Burn tax if any
981990
return tax;
982991
}

0 commit comments

Comments
 (0)