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

chore: fix audit issues #496

Merged
merged 9 commits into from
Feb 18, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions contracts/BSCValidatorSet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else if (Memory.compareStrings(key, "burnRatio")) {
require(value.length == 32, "length of burnRatio mismatch");
uint256 newBurnRatio = BytesToTypes.bytesToUint256(32, value);
require(newBurnRatio + systemRewardRatio <= BLOCK_FEES_RATIO_SCALE, "the burnRatio plus systemRewardRatio must be no greater than 10000");
require(newBurnRatio.add(systemRewardRatio) <= BLOCK_FEES_RATIO_SCALE, "the burnRatio plus systemRewardRatio must be no greater than 10000");
burnRatio = newBurnRatio;
} else if (Memory.compareStrings(key, "maxNumOfMaintaining")) {
require(value.length == 32, "length of maxNumOfMaintaining mismatch");
Expand Down Expand Up @@ -884,7 +884,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
} else if (Memory.compareStrings(key, "systemRewardRatio")) {
require(value.length == 32, "length of systemRewardRatio mismatch");
uint256 newSystemRewardRatio = BytesToTypes.bytesToUint256(32, value);
require(newSystemRewardRatio + burnRatio <= BLOCK_FEES_RATIO_SCALE, "the systemRewardRatio plus burnRatio must be no greater than 10000");
require(newSystemRewardRatio.add(burnRatio) <= BLOCK_FEES_RATIO_SCALE, "the systemRewardRatio plus burnRatio must be no greater than 10000");
systemRewardRatio = newSystemRewardRatio;
} else {
require(false, "unknown param");
Expand Down Expand Up @@ -930,11 +930,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
validatorExtraSet[i].isMaintaining = false;
validatorExtraSet[i].enterMaintenanceHeight = 0;
} else {
currentValidatorSet[i].votingPower = newValidatorSet[i].votingPower;
// update the vote address if it is different
if (!BytesLib.equal(newVoteAddrs[i], validatorExtraSet[i].voteAddress)) {
validatorExtraSet[i].voteAddress = newVoteAddrs[i];
}
currentValidatorSet[i].jailed = newValidatorSet[i].jailed;
}
}

Expand Down Expand Up @@ -968,7 +968,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
* Vote address is not considered
*/
function isSameValidator(Validator memory v1, Validator memory v2) private pure returns(bool) {
return v1.consensusAddress == v2.consensusAddress && v1.feeAddress == v2.feeAddress && v1.BBCFeeAddress == v2.BBCFeeAddress && v1.votingPower == v2.votingPower;
return v1.consensusAddress == v2.consensusAddress && v1.feeAddress == v2.feeAddress && v1.BBCFeeAddress == v2.BBCFeeAddress;
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
}

function getVoteAddresses(address[] memory validators) internal view returns(bytes[] memory) {
Expand Down Expand Up @@ -1074,11 +1074,11 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
uint256 averageDistribute = income / rest;
if (averageDistribute != 0) {
for (uint i; i<index; ++i) {
currentValidatorSet[i].incoming = currentValidatorSet[i].incoming + averageDistribute;
currentValidatorSet[i].incoming = currentValidatorSet[i].incoming.add(averageDistribute);
}
uint n = currentValidatorSet.length;
for (uint i=index+1; i<n; ++i) {
currentValidatorSet[i].incoming = currentValidatorSet[i].incoming + averageDistribute;
currentValidatorSet[i].incoming = currentValidatorSet[i].incoming.add(averageDistribute);
}
}

Expand Down Expand Up @@ -1111,7 +1111,7 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
if (averageDistribute != 0) {
uint n = currentValidatorSet.length;
for (uint i; i<n; ++i) {
currentValidatorSet[i].incoming = currentValidatorSet[i].incoming + averageDistribute;
currentValidatorSet[i].incoming = currentValidatorSet[i].incoming.add(averageDistribute);
}
}
return true;
Expand All @@ -1122,6 +1122,12 @@ contract BSCValidatorSet is IBSCValidatorSet, System, IParamSubscriber, IApplica
address validator;
bool isFelony;

for (uint i; i<_validatorSet.length; ++i) {
unclezoro marked this conversation as resolved.
Show resolved Hide resolved
if (_validatorSet[i].jailed) {
++numOfFelony;
}
}

// 1. validators exit maintenance
uint256 i;
// caution: it must calculate workingValidatorCount before _exitMaintenance loop
Expand Down
2 changes: 1 addition & 1 deletion contracts/SlashIndicator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract SlashIndicator is ISlashIndicator,System,IParamSubscriber, IApplication
uint256 public felonySlashRewardRatio;
bool public enableMaliciousVoteSlash;

uint256 public constant INIT_FELONY_SLASH_SCOPE = 86400; // 3 days
uint256 public constant INIT_FELONY_SLASH_SCOPE = 28800; // 1 days(block number)

uint256 public felonySlashScope;

Expand Down
1 change: 1 addition & 0 deletions contracts/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ contract Staking is IStaking, System, IParamSubscriber, IApplication {
if (isAutoUndelegate) {
delegated[recipient] = delegated[recipient].sub(amount);
delegatedOfValidator[recipient][validator] = delegatedOfValidator[recipient][validator].sub(amount);
emit undelegateSuccess(recipient, validator, amount);
}

emit undelegatedReceived(recipient, validator, amount);
Expand Down