You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a CEI (Checks-Effects-Interactions) pattern violation in FxERC20ChildTunnel.sol.
In costructor() assignment value tokenTemplate = _tokenTemplate; before _isContract(_tokenTemplate) check:
constructor(address_fxChild, address_tokenTemplate) FxBaseChildTunnel(_fxChild) {
tokenTemplate = _tokenTemplate; // Effect on state variablerequire(_isContract(_tokenTemplate), "Token template is not contract"); // Check
}
so the code should look like this:
constructor(address_fxChild, address_tokenTemplate) FxBaseChildTunnel(_fxChild) {
require(_isContract(_tokenTemplate), "Token template is not contract"); // Check
tokenTemplate = _tokenTemplate; // Interaction with state variable
}
Also in _mapToken() function where IFxERC20(childToken).initialize() called before rootToChildToken[rootToken] = childToken:
function _mapToken(bytesmemorysyncData) internalreturns (address) {
(addressrootToken, stringmemoryname, stringmemorysymbol, uint8decimals) =abi.decode(
syncData,
(address, string, string, uint8)
);
// get root to child tokenaddress childToken = rootToChildToken[rootToken];
// check if it's already mappedrequire(childToken ==address(0x0), "FxERC20ChildTunnel: ALREADY_MAPPED");
// deploy new child tokenbytes32 salt =keccak256(abi.encodePacked(rootToken));
childToken =createClone(salt, tokenTemplate);
// slither-disable-next-line reentrancy-no-ethIFxERC20(childToken).initialize(
address(this),
rootToken,
string(abi.encodePacked(name, SUFFIX_NAME)),
string(abi.encodePacked(PREFIX_SYMBOL, symbol)),
decimals
); // Interaction with childToken// map the token
rootToChildToken[rootToken] = childToken; // Effect on state variableemitTokenMapped(rootToken, childToken);
// return new child tokenreturn childToken;
}
and code should look like:
function _mapToken(bytesmemorysyncData) internalreturns (address) {
(addressrootToken, stringmemoryname, stringmemorysymbol, uint8decimals) =abi.decode(
syncData,
(address, string, string, uint8)
);
// get root to child tokenaddress childToken = rootToChildToken[rootToken];
// check if it's already mappedrequire(childToken ==address(0x0), "FxERC20ChildTunnel: ALREADY_MAPPED");
// deploy new child tokenbytes32 salt =keccak256(abi.encodePacked(rootToken));
childToken =createClone(salt, tokenTemplate);
// map the token
rootToChildToken[rootToken] = childToken; // Effect on state variable// slither-disable-next-line reentrancy-no-ethIFxERC20(childToken).initialize(
address(this),
rootToken,
string(abi.encodePacked(name, SUFFIX_NAME)),
string(abi.encodePacked(PREFIX_SYMBOL, symbol)),
decimals
); // Interaction with childTokenemitTokenMapped(rootToken, childToken);
// return new child tokenreturn childToken;
}
These changes reduce gas cost if some of these checks will revert an error, before effects/interactions.
The text was updated successfully, but these errors were encountered:
There is a CEI (Checks-Effects-Interactions) pattern violation in FxERC20ChildTunnel.sol.
In
costructor()
assignment valuetokenTemplate = _tokenTemplate;
before_isContract(_tokenTemplate)
check:so the code should look like this:
Also in
_mapToken()
function whereIFxERC20(childToken).initialize()
called beforerootToChildToken[rootToken] = childToken
:and code should look like:
These changes reduce gas cost if some of these checks will revert an error, before effects/interactions.
The text was updated successfully, but these errors were encountered: