Skip to content

Commit

Permalink
Fix some issues raised by Slither
Browse files Browse the repository at this point in the history
  • Loading branch information
Doy-lee committed Oct 9, 2024
1 parent 599bb2e commit 484a323
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ analyze:
# rewind time by up to 24 hours or, 1 hr into the future.
slither . \
--filter-paths node_modules\|contracts/test \
--exclude timestamp
--exclude timestamp,naming-convention,assembly

fuzz:
echidna . --contract ServiceNodeContributionEchidnaTest --config echidna-local.config.yml
Expand Down
26 changes: 16 additions & 10 deletions contracts/ServiceNodeContribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -289,23 +289,29 @@ contract ServiceNodeContribution is Shared, IServiceNodeContribution {
// NOTE: Check contract collateralisation _after_ the amount is
// committed to the contract to ensure contribution sums are all
// accounted for.
if ((totalContribution() + totalReservedContribution()) > stakingRequirement)
revert ContributionExceedsStakingRequirement(totalContribution(), totalReservedContribution(), stakingRequirement);
uint256 currTotalContribution = totalContribution();
uint256 currReservedContribution = totalReservedContribution();
if ((currTotalContribution + currReservedContribution) > stakingRequirement)
revert ContributionExceedsStakingRequirement(currTotalContribution, currReservedContribution, stakingRequirement);

if (_contributorAddresses.length > maxContributors)
revert MaxContributorsExceeded(maxContributors);

emit NewContribution(caller, amount);
// NOTE: Allow finalizing the node if the staking requirement is met
// State transition before calling out to external code to mitigate
// re-entrancy.
if (currTotalContribution == stakingRequirement) {
emit Filled(_serviceNodeParams.serviceNodePubkey, operator);
status = Status.WaitForFinalized;
}

// NOTE: Transfer funds from sender to contract
emit NewContribution(caller, amount);
SENT.safeTransferFrom(caller, address(this), amount);

// NOTE: Allow finalizing the node if the staking requirement is met
if (totalContribution() == stakingRequirement) {
emit Filled(_serviceNodeParams.serviceNodePubkey, operator);
status = Status.WaitForFinalized;
if (!manualFinalize) // Auto finalize if allowed
_finalize();
// NOTE: Auto finalize the node if valid
if (status == Status.WaitForFinalized && !manualFinalize) {
_finalize();
}
}

Expand Down Expand Up @@ -348,7 +354,7 @@ contract ServiceNodeContribution is Shared, IServiceNodeContribution {

// NOTE: Remove all reserved contributions
{
IServiceNodeRewards.ReservedContributor[] memory zero;
IServiceNodeRewards.ReservedContributor[] memory zero = new IServiceNodeRewards.ReservedContributor[](0);
_updateReservedContributors(zero);
}
}
Expand Down

0 comments on commit 484a323

Please sign in to comment.