Skip to content

Commit 2706d20

Browse files
satyamakgecadamdossa
authored andcommitted
Fix the BalanceOfPartition audit item (#679)
* fix balance of partition function * fix balance of Partition function * return balance in the parent implementation of the getTokensByPartition()
1 parent 95338da commit 2706d20

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

contracts/modules/TransferManager/TransferManager.sol

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ contract TransferManager is ITransferManager, Module {
2020

2121
/**
2222
* @notice return the amount of tokens for a given user as per the partition
23+
* @dev returning the balance of token holder against the UNLOCKED partition.
24+
* This condition is valid only when the base contract doesn't implement the
25+
* `getTokensByPartition()` function.
2326
*/
24-
function getTokensByPartition(bytes32 /*_partition*/, address /*_tokenHolder*/, uint256 /*_additionalBalance*/) external view returns(uint256) {
25-
return 0;
27+
function getTokensByPartition(bytes32 _partition, address _tokenHolder, uint256 /*_additionalBalance*/) external view returns(uint256) {
28+
if (_partition == UNLOCKED)
29+
return ISecurityToken(securityToken).balanceOf(_tokenHolder);
30+
return uint256(0);
2631
}
2732

2833
}

contracts/tokens/SecurityToken.sol

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,13 +486,20 @@ contract SecurityToken is ERC20, ReentrancyGuard, SecurityTokenStorage, IERC1594
486486
return _balanceOfByPartition(_partition, _tokenHolder, 0);
487487
}
488488

489-
function _balanceOfByPartition(bytes32 _partition, address _tokenHolder, uint256 _additionalBalance) internal view returns(uint256 max) {
489+
function _balanceOfByPartition(bytes32 _partition, address _tokenHolder, uint256 _additionalBalance) internal view returns(uint256 partitionBalance) {
490490
address[] memory tms = modules[TRANSFER_KEY];
491491
uint256 amount;
492492
for (uint256 i = 0; i < tms.length; i++) {
493493
amount = ITransferManager(tms[i]).getTokensByPartition(_partition, _tokenHolder, _additionalBalance);
494-
if (max < amount) {
495-
max = amount;
494+
// In UNLOCKED partition we are returning the minimum of all the unlocked balances
495+
if (_partition == UNLOCKED) {
496+
if (amount < partitionBalance || i == 0)
497+
partitionBalance = amount;
498+
}
499+
// In locked partition we are returning the maximum of all the Locked balances
500+
else {
501+
if (partitionBalance < amount)
502+
partitionBalance = amount;
496503
}
497504
}
498505
}

0 commit comments

Comments
 (0)