Skip to content

Commit

Permalink
Fix audit report (#7)
Browse files Browse the repository at this point in the history
* [CRITICAL] Fix lastDateSync

* [LOW] Prevent duplicated governor

* [INFO] Fix test
  • Loading branch information
ducthotran2010 authored May 14, 2022
1 parent c09ef25 commit 6cd7240
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
1 change: 1 addition & 0 deletions contracts/v0.8/common/RoninValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ contract RoninValidator is Initializable, IWeightedValidator, HasProxyAdmin {
_totalWeights += _v.weight;

if (_governors[_i] != _v.governor) {
require(_governorWeight[_v.governor] == 0, "RoninValidator: query for duplicated governor");
delete _governorWeight[_governors[_i]];
_governors[_i] = _v.governor;
}
Expand Down
10 changes: 5 additions & 5 deletions contracts/v0.8/extensions/WithdrawalLimitation.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ abstract contract WithdrawalLimitation is HasProxyAdmin {
mapping(address => uint256) public dailyWithdrawalLimit;
/// @dev Mapping from token address => today withdrawal amount
mapping(address => uint256) public lastSyncedWithdrawal;
/// @dev Last date synced to record the `lastSyncedWithdrawal`
uint256 public lastDateSynced;
/// @dev Mapping from token address => last date synced to record the `lastSyncedWithdrawal`
mapping(address => uint256) public lastDateSynced;

/**
* @dev Sets the thresholds for withdrawals that requires all validator signatures.
Expand Down Expand Up @@ -187,7 +187,7 @@ abstract contract WithdrawalLimitation is HasProxyAdmin {
}

uint256 _currentDate = block.timestamp / 1 days;
if (_currentDate > lastDateSynced) {
if (_currentDate > lastDateSynced[_token]) {
return dailyWithdrawalLimit[_token] <= _quantity;
} else {
return dailyWithdrawalLimit[_token] <= lastSyncedWithdrawal[_token] + _quantity;
Expand All @@ -199,8 +199,8 @@ abstract contract WithdrawalLimitation is HasProxyAdmin {
*/
function _recordWithdrawal(address _token, uint256 _quantity) internal virtual {
uint256 _currentDate = block.timestamp / 1 days;
if (_currentDate > lastDateSynced) {
lastDateSynced = _currentDate;
if (_currentDate > lastDateSynced[_token]) {
lastDateSynced[_token] = _currentDate;
lastSyncedWithdrawal[_token] = _quantity;
} else {
lastSyncedWithdrawal[_token] += _quantity;
Expand Down
4 changes: 2 additions & 2 deletions test/v0.8/mainchain/MainchainGatewayV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('Mainchain Gateway V2 test', () => {
await erc20.addMinters([deployer.address]);
erc721 = await new MockERC721__factory(deployer).deploy('ERC721', 'ERC721', '');

if ((network.name = Network.Hardhat)) {
if (network.name == Network.Hardhat) {
validatorSet[network.name] = validators.map((v, i) => ({
validator: v.address,
governor: governors[i].address,
Expand Down Expand Up @@ -401,7 +401,7 @@ describe('Mainchain Gateway V2 test', () => {
expect(receipt.gasUsed).lt(60_000);
});

it('Should be able to deposit empty amount', async () => {
it('Should not be able to deposit empty amount', async () => {
await expect(
normalUser.sendTransaction({
to: gateway.address,
Expand Down

0 comments on commit 6cd7240

Please sign in to comment.