Skip to content

Commit

Permalink
All/pre audit code fixes (#58)
Browse files Browse the repository at this point in the history
* Make IUpgradableToken an interface

* More descriptive name for Upgrade event param

* Make events indexed

* Fix too long lines

* Update event name

* Add mock functions ensuring that internal functions are declared as internal

* Remove extra modifier from mintable
  • Loading branch information
truls authored and peteremiljensen committed Jan 13, 2019
1 parent 063917b commit d31e501
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 25 deletions.
8 changes: 5 additions & 3 deletions contracts/TokenManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ contract TokenManager is Ownable {
mapping (bytes32 => TokenEntry) private tokens;
bytes32[] private names;

event TokenAdded(bytes32 name, ITokenX addr);
event TokenDeleted(bytes32 name, ITokenX addr);
event TokenUpgraded(bytes32 name, ITokenX from, ITokenX to);
event TokenAdded(bytes32 indexed name, ITokenX indexed addr);
event TokenDeleted(bytes32 indexed name, ITokenX indexed addr);
event TokenUpgraded(bytes32 indexed name,
ITokenX indexed from,
ITokenX indexed to);

/**
* @dev Require that the token _name exists
Expand Down
27 changes: 27 additions & 0 deletions contracts/mocks/ExternalERC20MintableMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,31 @@ contract ExternalERC20MintableMock is ExternalERC20Mintable, MinterRoleMock {
function changeMintingRecipient(address to) public {
_changeMintingRecipient(msg.sender, to);
}

/** Triggers compilation error if _changeMintingRecipient
* function is not declared internal
*/
function _changeMintingRecipient(
address sender,
address mintingRecip
)
internal
{
super._changeMintingRecipient(sender, mintingRecip);
}

/** Triggers compilation error if _mintExplicitSender
* function is not declared internal
*/
function _mintExplicitSender(
address sender,
address to,
uint256 value
)
internal
requireMinter(sender)
{
super._mintExplicitSender(sender, to, value);
}

}
5 changes: 3 additions & 2 deletions contracts/token/ERC20/ExternalERC20Storage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ contract ExternalERC20Storage is Ownable {

address private _implementor;

event StorageInitialImplementorSet(address to);
event StorageImplementorTransferred(address from, address to);
event StorageInitialImplementorSet(address indexed to);
event StorageImplementorTransferred(address indexed from,
address indexed to);

/**
* @dev Returns whether the sender is an implementor.
Expand Down
38 changes: 22 additions & 16 deletions contracts/token/IUpgradableTokenX.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pragma solidity ^0.4.24;

contract IUpgradableTokenX {
interface IUpgradableTokenX {

event Transfer(address indexed from,
address indexed to,
Expand All @@ -14,72 +14,78 @@ contract IUpgradableTokenX {
function finalizeUpgrade() external;

/* Taken from ERC20Detailed in openzeppelin-solidity */
function nameExplicitSender(address sender) public view returns(string);
function nameExplicitSender(address sender) external view returns(string);

function symbolExplicitSender(address sender) public view returns(string);
function symbolExplicitSender(address sender)
external
view
returns(string);

function decimalsExplicitSender(address sender) public view returns(uint8);
function decimalsExplicitSender(address sender)
external
view
returns(uint8);

/* Taken from IERC20 in openzeppelin-solidity */
function totalSupplyExplicitSender(address sender)
public
external
view
returns (uint256);

function balanceOfExplicitSender(address sender, address who)
public
external
view
returns (uint256);

function allowanceExplicitSender(address sender,
address owner,
address spender)
public
external
view
returns (uint256);

function transferExplicitSender(address sender, address to, uint256 value)
public
external
returns (bool);

function approveExplicitSender(address sender,
address spender,
uint256 value)
public
external
returns (bool);

function transferFromExplicitSender(address sender,
address from,
address to,
uint256 value)
public
external
returns (bool);

function mintExplicitSender(address sender, address to, uint256 value)
public
external
returns (bool);

function changeMintingRecipientExplicitSender(address sender,
address mintingRecip)
public;
external;

function burnExplicitSender(address sender, uint256 value) public;
function burnExplicitSender(address sender, uint256 value) external;

function burnFromExplicitSender(address sender,
address from,
uint256 value)
public;
external;

function increaseAllowanceExplicitSender(address sender,
address spender,
uint addedValue)
public
external
returns (bool success);

function decreaseAllowanceExplicitSender(address sender,
address spender,
uint subtractedValue)
public
external
returns (bool success);

}
2 changes: 1 addition & 1 deletion contracts/token/TokenX.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract TokenX is ITokenX, TokenXExplicitSender {
}
}

event Upgraded(address to);
event Upgraded(address indexed to);

function isUpgraded() public view returns (bool) {
return upgradedToken != IUpgradableTokenX(0);
Expand Down
2 changes: 1 addition & 1 deletion contracts/token/TokenXExplicitSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ contract TokenXExplicitSender is IUpgradableTokenX,

bool private enabled;

event UpgradeFinalized(address c, address sender);
event UpgradeFinalized(address indexed upgradedFrom, address indexed sender);

/**
* @param name The name of the token
Expand Down
2 changes: 1 addition & 1 deletion test/token/TokenX.events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const utils = require('./../utils.js');
module.exports = utils.makeEventMap({
upgrade: (contract, oldContract) => [
{ eventName: 'UpgradeFinalized',
paramMap: { c: oldContract,
paramMap: { upgradedFrom: oldContract,
sender: oldContract } },
{ eventName: 'Upgraded',
paramMap: { to: contract } }] });
2 changes: 1 addition & 1 deletion test/token/TokenXExplicitSender.events.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ const utils = require('./../utils.js');
module.exports = utils.makeEventMap({
finalizeUpgrade: (contract, senderAddr) => [{
eventName: 'UpgradeFinalized',
paramMap: { c: contract,
paramMap: { upgradedFrom: contract,
sender: senderAddr } }] });

0 comments on commit d31e501

Please sign in to comment.