Skip to content

Commit b02f558

Browse files
pedromauri-rsk
authored andcommitted
Remove isValidatingAllowedTokens as it will never be false
Change sugested by version 2 Audit Remove disableAllowedTokensValidation method as well
1 parent d2a3596 commit b02f558

File tree

8 files changed

+83
-457
lines changed

8 files changed

+83
-457
lines changed

abis/AllowTokens.json

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,6 @@
3838
"name": "AllowedTokenRemoved",
3939
"type": "event"
4040
},
41-
{
42-
"anonymous": false,
43-
"inputs": [
44-
{
45-
"indexed": false,
46-
"internalType": "bool",
47-
"name": "_enabled",
48-
"type": "bool"
49-
}
50-
],
51-
"name": "AllowedTokenValidation",
52-
"type": "event"
53-
},
5441
{
5542
"anonymous": false,
5643
"inputs": [
@@ -184,7 +171,7 @@
184171
}
185172
],
186173
"indexed": false,
187-
"internalType": "struct AllowTokens.Limits",
174+
"internalType": "struct IAllowTokens.Limits",
188175
"name": "limits",
189176
"type": "tuple"
190177
}
@@ -319,21 +306,6 @@
319306
"stateMutability": "view",
320307
"type": "function"
321308
},
322-
{
323-
"constant": true,
324-
"inputs": [],
325-
"name": "isValidatingAllowedTokens",
326-
"outputs": [
327-
{
328-
"internalType": "bool",
329-
"name": "",
330-
"type": "bool"
331-
}
332-
],
333-
"payable": false,
334-
"stateMutability": "view",
335-
"type": "function"
336-
},
337309
{
338310
"constant": true,
339311
"inputs": [],
@@ -567,12 +539,12 @@
567539
"type": "uint256"
568540
}
569541
],
570-
"internalType": "struct AllowTokens.Limits",
542+
"internalType": "struct IAllowTokens.Limits",
571543
"name": "limits",
572544
"type": "tuple"
573545
}
574546
],
575-
"internalType": "struct AllowTokens.TypeInfo[]",
547+
"internalType": "struct IAllowTokens.TypeInfo[]",
576548
"name": "typesInfo",
577549
"type": "tuple[]"
578550
}
@@ -632,7 +604,7 @@
632604
"type": "uint256"
633605
}
634606
],
635-
"internalType": "struct AllowTokens.TokenInfo",
607+
"internalType": "struct IAllowTokens.TokenInfo",
636608
"name": "info",
637609
"type": "tuple"
638610
},
@@ -664,7 +636,7 @@
664636
"type": "uint256"
665637
}
666638
],
667-
"internalType": "struct AllowTokens.Limits",
639+
"internalType": "struct IAllowTokens.Limits",
668640
"name": "limit",
669641
"type": "tuple"
670642
}
@@ -756,7 +728,7 @@
756728
"type": "uint256"
757729
}
758730
],
759-
"internalType": "struct AllowTokens.Limits",
731+
"internalType": "struct IAllowTokens.Limits",
760732
"name": "limits",
761733
"type": "tuple"
762734
}
@@ -809,7 +781,7 @@
809781
"type": "uint256"
810782
}
811783
],
812-
"internalType": "struct AllowTokens.Limits",
784+
"internalType": "struct IAllowTokens.Limits",
813785
"name": "limits",
814786
"type": "tuple"
815787
}
@@ -943,7 +915,7 @@
943915
"type": "uint256"
944916
}
945917
],
946-
"internalType": "struct AllowTokens.TokensAndType[]",
918+
"internalType": "struct IAllowTokens.TokensAndType[]",
947919
"name": "tokensAndTypes",
948920
"type": "tuple[]"
949921
}
@@ -969,24 +941,6 @@
969941
"stateMutability": "nonpayable",
970942
"type": "function"
971943
},
972-
{
973-
"constant": false,
974-
"inputs": [],
975-
"name": "enableAllowedTokensValidation",
976-
"outputs": [],
977-
"payable": false,
978-
"stateMutability": "nonpayable",
979-
"type": "function"
980-
},
981-
{
982-
"constant": false,
983-
"inputs": [],
984-
"name": "disableAllowedTokensValidation",
985-
"outputs": [],
986-
"payable": false,
987-
"stateMutability": "nonpayable",
988-
"type": "function"
989-
},
990944
{
991945
"constant": false,
992946
"inputs": [

abis/Bridge.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@
333333
"name": "allowTokens",
334334
"outputs": [
335335
{
336-
"internalType": "contract AllowTokens",
336+
"internalType": "contract IAllowTokens",
337337
"name": "",
338338
"type": "address"
339339
}

bridge/contracts/AllowTokens.sol

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ contract AllowTokens is Initializable, UpgradableOwnable, UpgradableSecondary, I
1414

1515
address constant private NULL_ADDRESS = address(0);
1616
uint256 constant public MAX_TYPES = 250;
17-
bool public isValidatingAllowedTokens;
1817
mapping (address => bool) public allowedContracts;
1918
mapping (address => TokenInfo) public allowedTokens;
2019
mapping (uint256 => Limits) public typeLimits;
@@ -26,7 +25,6 @@ contract AllowTokens is Initializable, UpgradableOwnable, UpgradableSecondary, I
2625

2726
event SetToken(address indexed _tokenAddress, uint256 _typeId);
2827
event AllowedTokenRemoved(address indexed _tokenAddress);
29-
event AllowedTokenValidation(bool _enabled);
3028
event AllowedContractAdded(address indexed _contractAddress);
3129
event AllowedContractRemoved(address indexed _contractAddress);
3230
event TokenTypeAdded(uint256 indexed _typeId, string _typeDescription);
@@ -50,7 +48,6 @@ contract AllowTokens is Initializable, UpgradableOwnable, UpgradableSecondary, I
5048
UpgradableOwnable.initialize(_manager);
5149
UpgradableSecondary.initialize(_primary);
5250
_setConfirmations(_smallAmountConfirmations, _mediumAmountConfirmations, _largeAmountConfirmations);
53-
isValidatingAllowedTokens = true;
5451
for(uint i = 0; i < typesInfo.length; i = i + 1) {
5552
_addTokenType(typesInfo[i].description, typesInfo[i].limits);
5653
}
@@ -86,21 +83,20 @@ contract AllowTokens is Initializable, UpgradableOwnable, UpgradableSecondary, I
8683
// solium-disable-next-line max-len
8784
function updateTokenTransfer(address token, uint256 amount) external onlyPrimary returns(uint256 typeId) {
8885
(TokenInfo memory info, Limits memory limit) = getInfoAndLimits(token);
89-
if(isValidatingAllowedTokens) {
90-
require(isTokenAllowed(token), "AllowTokens: Token not whitelisted");
91-
require(amount >= limit.min, "AllowTokens: Amount lower than limit");
92-
// solium-disable-next-line security/no-block-members
93-
if (now > info.lastDay + 24 hours) {
94-
// solium-disable-next-line security/no-block-members
95-
info.lastDay = now;
96-
info.spentToday = 0;
97-
}
98-
uint maxWithdraw = _calcMaxWithdraw(info, limit);
99-
require(amount <= maxWithdraw, "AllowTokens: Amount bigger than limit");
100-
info.spentToday = info.spentToday.add(amount);
101-
allowedTokens[token] = info;
102-
emit UpdateTokensTransfered(token, info.lastDay, info.spentToday);
86+
require(isTokenAllowed(token), "AllowTokens: Token not whitelisted");
87+
require(amount >= limit.min, "AllowTokens: Amount lower than limit");
88+
// solium-disable-next-line security/no-block-members
89+
if (now > info.lastDay + 24 hours) {
90+
// solium-disable-next-line security/no-block-members
91+
info.lastDay = now;
92+
info.spentToday = 0;
10393
}
94+
uint maxWithdraw = _calcMaxWithdraw(info, limit);
95+
require(amount <= maxWithdraw, "AllowTokens: Amount bigger than limit");
96+
info.spentToday = info.spentToday.add(amount);
97+
allowedTokens[token] = info;
98+
emit UpdateTokensTransfered(token, info.lastDay, info.spentToday);
99+
104100
return info.typeId;
105101
}
106102

@@ -151,10 +147,7 @@ contract AllowTokens is Initializable, UpgradableOwnable, UpgradableSecondary, I
151147
}
152148

153149
function isTokenAllowed(address token) public view notNull(token) returns (bool) {
154-
if (isValidatingAllowedTokens) {
155-
return allowedTokens[token].allowed;
156-
}
157-
return true;
150+
return allowedTokens[token].allowed;
158151
}
159152

160153
function setToken(address token, uint256 typeId) public notNull(token) {
@@ -182,16 +175,6 @@ contract AllowTokens is Initializable, UpgradableOwnable, UpgradableSecondary, I
182175
emit AllowedTokenRemoved(token);
183176
}
184177

185-
function enableAllowedTokensValidation() external onlyOwner {
186-
isValidatingAllowedTokens = true;
187-
emit AllowedTokenValidation(isValidatingAllowedTokens);
188-
}
189-
190-
function disableAllowedTokensValidation() external onlyOwner {
191-
isValidatingAllowedTokens = false;
192-
emit AllowedTokenValidation(isValidatingAllowedTokens);
193-
}
194-
195178
function setConfirmations(
196179
uint256 _smallAmountConfirmations,
197180
uint256 _mediumAmountConfirmations,

bridge/contracts/test/mockReceiveTokensCall.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ contract mockReceiveTokensCall is IERC777Recipient {
2929
IERC777(tokenToUse).send(bridge, amount, data);
3030
}
3131

32+
// Mandatory for IERC777Recipient
3233
function tokensReceived(
33-
address operator,
34-
address from,
35-
address to,
36-
uint amount,
37-
bytes calldata userData,
38-
bytes calldata operatorData
34+
address,
35+
address,
36+
address,
37+
uint,
38+
bytes calldata,
39+
bytes calldata
3940
) external {
4041
this;
4142
}

0 commit comments

Comments
 (0)