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
I want to track the state variable writes in the function MinterRole._addMinter(address), but I found that it only correctly returns the state variable _minters that the function read.
Then I tried to insert the following code snippet in the function.py , and it was able to solve the problem, but I feel it's not elegant enough.
+# consider state variables written in library calls+fromslither.slithir.operationsimportLibraryCall+lbc_nodes= [xforxinself.nodesifx.library_calls]
+fornodeinlbc_nodes:
+foririnnode.irs:
+ifnotisinstance(ir, LibraryCall):
+continue+for (param, arg) inzip(ir.function.parameters, ir.arguments):
+ifparaminir.function.variables_writtenandisinstance(arg, StateVariable):
+ifargnotinself._state_vars_written:
+self._state_vars_written.append(arg)
Code example to reproduce the issue:
Library:
libraryRoles {
struct Role {
mapping (address=>bool) bearer;
}
/** * @dev Give an account access to this role. */function add(Role storagerole, addressaccount) internal {
require(!has(role, account), "Roles: account already has role");
role.bearer[account] =true;
}
/** * @dev Remove an account's access to this role. */function remove(Role storagerole, addressaccount) internal {
require(has(role, account), "Roles: account does not have role");
role.bearer[account] =false;
}
/** * @dev Check if an account has this role. * @return bool */function has(Role storagerole, addressaccount) internalviewreturns (bool) {
require(account !=address(0), "Roles: account is the zero address");
return role.bearer[account];
}
}
Contract:
pragma solidity^0.5.0;
contractContext {
// Empty internal constructor, to prevent people from mistakenly deploying// an instance of this contract, which should be used via inheritance.constructor () internal { }
// solhint-disable-previous-line no-empty-blocksfunction _msgSender() internalviewreturns (address payable) {
returnmsg.sender;
}
function _msgData() internalviewreturns (bytesmemory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691returnmsg.data;
}
}
contractMinterRoleisContext {
using Rolesfor Roles.Role;
event MinterAdded(addressindexedaccount);
event MinterRemoved(addressindexedaccount);
Roles.Role private _minters;
constructor () internal {
_addMinter(_msgSender());
}
modifier onlyMinter() {
require(isMinter(_msgSender()), "MinterRole: caller does not have the Minter role");
_;
}
function isMinter(addressaccount) publicviewreturns (bool) {
return _minters.has(account);
}
function addMinter(addressaccount) public onlyMinter {
_addMinter(account);
}
function renounceMinter() public {
_removeMinter(_msgSender());
}
function _addMinter(addressaccount) internal {
_minters.add(account);
emitMinterAdded(account);
}
function _removeMinter(addressaccount) internal {
_minters.remove(account);
emitMinterRemoved(account);
}
}
Version:
0.10.4
Relevant log output:
No response
The text was updated successfully, but these errors were encountered:
Describe the issue:
I want to track the state variable writes in the function MinterRole._addMinter(address), but I found that it only correctly returns the state variable _minters that the function read.
Then I tried to insert the following code snippet in the function.py , and it was able to solve the problem, but I feel it's not elegant enough.
Code example to reproduce the issue:
Library:
Contract:
Version:
0.10.4
Relevant log output:
No response
The text was updated successfully, but these errors were encountered: