Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Solidity 0.5.16 #499

Merged
merged 15 commits into from Apr 22, 2020
Merged

Upgrade to Solidity 0.5.16 #499

merged 15 commits into from Apr 22, 2020

Conversation

jjgonecrypto
Copy link
Contributor

@jjgonecrypto jjgonecrypto commented Apr 18, 2020

Here's the Solidity v5 upgrade branch. The lion's share of the effort was from @K-Ho 馃檱; I cherry-picked his commits and massaged them into our develop branch.

Notes

  1. MixinResolver, SelfDestructible and Pausable are now all abstract. This is because they inherit from Owned but don't invoke the Owned constructor (this is as intended, so that we don't have the "Base constructor used twice issue"
  2. All compiler warnings are now gone 馃槷
  3. I opted for the more permissive semver of solc ^0.516 (i.e. 0.5.x) - happy to discuss being more restrictive.

Note: I've opted to keep this upgrade separate from testing Solidity v4 and v5 side-by-side, in order to keep this PR down in size. After merging, I'll work on that.

@codecov
Copy link

codecov bot commented Apr 18, 2020

Codecov Report

Merging #499 into develop will increase coverage by 0.55%.
The diff coverage is 92.57%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #499      +/-   ##
===========================================
+ Coverage    92.04%   92.59%   +0.55%     
===========================================
  Files           39       38       -1     
  Lines         1985     1984       -1     
  Branches       271      275       +4     
===========================================
+ Hits          1827     1837      +10     
+ Misses         158      147      -11     
Impacted Files Coverage 螖
contracts/EscrowChecker.sol 0.00% <0.00%> (酶)
contracts/FeePoolEternalStorage.sol 20.00% <0.00%> (酶)
contracts/IssuanceEternalStorage.sol 100.00% <酶> (酶)
contracts/LimitedSetup.sol 100.00% <酶> (酶)
contracts/Math.sol 100.00% <酶> (酶)
contracts/MultiCollateralSynth.sol 88.23% <酶> (酶)
contracts/Owned.sol 100.00% <酶> (酶)
contracts/RewardsDistributionRecipient.sol 100.00% <酶> (酶)
contracts/SynthetixState.sol 91.66% <酶> (酶)
contracts/EternalStorage.sol 25.58% <33.33%> (酶)
... and 28 more

Continue to review full report at Codecov.

Legend - Click here to learn more
螖 = absolute <relative> (impact), 酶 = not affected, ? = missing data
Powered by Codecov. Last update c67c34d...13807c1. Read the comment docs.

@jjgonecrypto jjgonecrypto marked this pull request as ready for review April 18, 2020 18:58
* @param feePeriodIDs Array feePeriodIDs with the accounts last claim
*/
function importFeeWithdrawalData(address[] accounts, uint[] feePeriodIDs) external onlyOwner onlyDuringSetup {
function importFeeWithdrawalData(address[] calldata accounts, uint[] calldata feePeriodIDs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for removing the natspec comments?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're removing natspec altogether in favor of the docs. Natspec doesn't currently support state variables and internal functions which we want to include in our docs...

Comment on lines +181 to +183
if (!success) {
// Note: we're ignoring the return value as it will fail for contracts that do not implement RewardsDistributionRecipient.sol
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any need of having this empty if statement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It prevents the compiler warning for not doing anything with the result

contracts/State.sol Outdated Show resolved Hide resolved
* @param _resolver The address of the Synthetix Address Resolver
*/
constructor(address _proxy, TokenState _tokenState, address _owner, uint _totalSupply, address _resolver)
constructor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

natspec comments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ibid)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rip

contracts/test-helpers/MockExchanger.sol Outdated Show resolved Hide resolved
contracts/test-helpers/MockExchanger.sol Outdated Show resolved Hide resolved
@jjgonecrypto
Copy link
Contributor Author

PR feedback addressed @maxsam4 - RFAL


import "./EternalStorage.sol";


// TODO: this contract is redundant and should be removed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this redundant? Can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is redundant, but removing it requires updating our test setup script, deploy script and our deployment.json files. As for naming, both it and DelegateApprovals should use the [Base][Instance] ordering. E.g. ProxyFeePool, TokenStatesUSD.
For EternalStorage instances, we should have EternalStateIssuer and EternalStateDelegateApprovals. This makes it much easier to reason about naming.

/**
* @dev Owned Constructor
*/
// /**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well remove these natspec comments right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but let me do that in a follow up PR where I ensure everything is in the docs that need to be.

@@ -20,10 +20,14 @@ contract Proxy is Owned {
useDELEGATECALL = value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think its time to remove the useDELEGATECALL path. We never used it and it should never be used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Again, I'd like to do it in a follow up PR

@@ -17,17 +17,20 @@ contract Proxyable is Owned {
* optionalProxy modifiers, otherwise their invocations can use stale values. */
address public messageSender;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vote to remove the public accessor from messageSender. It used to be omitted and during an audit it was put back in from remediations however etherscan now always shows the last address that called the contract on the contract.... it was optically better hidden

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seconded. Though this should be in its own PR.

@@ -70,6 +70,6 @@ contract PurgeableSynth is Synth {
bytes32 private constant PURGED_SIG = keccak256("Purged(address,uint256)");

function emitPurged(address account, uint value) internal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clementbalestrat @evgenyboxer from support issue today user asked where his iETH is that disappeared. We really need the exchange to show users they were purged out of a frozen iSynth and their inverse synth is now in sUSD

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. We need Zoe to have a thought about it.

}

/**
* @notice Set the beneficiary address of this contract.
* @dev Only the contract owner may call this. The provided beneficiary must be non-null.
* @param _beneficiary The address to pay any eth contained in this contract to upon self-destruction.
*/
function setSelfDestructBeneficiary(address _beneficiary) external onlyOwner {
function setSelfDestructBeneficiary(address payable _beneficiary) external onlyOwner {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is not part of this review but I would question if we event need a setSelfDestructBeneficiary anymore and our contracts would look optically better without setting a selfDestructBeneficiary address that gets all "funds" when blown up... It's only for ETH anyways and we have no contracts that need ETH sent to us that blow up. We definitely shouldn't use this for ETH collateral either. Doesn't look good to let the owner use selfdestruct on a contract and get sent all the ETH

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good point , worth a discussion (though separate PR).

uint public constant MAX_MINTER_REWARD = 200 * SafeDecimalMath.unit();
// TODO Uncomment constant
/*constant*/
uint public MAX_MINTER_REWARD = 200 * SafeDecimalMath.unit();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wanna do 1e18 * 200 like the others?

Also thats the TODO

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah missed this, good spot.

* @param _resolver The address of the Synthetix Address Resolver
*/
constructor(address _proxy, TokenState _tokenState, address _owner, uint _totalSupply, address _resolver)
constructor(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rip



// https://docs.synthetix.io/contracts/SynthetixState
contract SynthetixState is State, LimitedSetup {
contract SynthetixState is Owned, State, LimitedSetup {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I much prefer how Owned has been lifted out

@@ -38,20 +39,18 @@ contract SynthetixState is State, LimitedSetup {
// may not be issued against a given value of SNX.
uint public issuanceRatio = SafeDecimalMath.unit() / 5;
// No more synths may be issued than the value of SNX backing them.
uint constant MAX_ISSUANCE_RATIO = SafeDecimalMath.unit();
// TODO Uncomment constant
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mistake. Good catch

@@ -123,19 +128,30 @@ contract ExternStateToken is SelfDestructible, Proxyable {
}

/* ========== EVENTS ========== */
function addressToBytes32(address input) internal pure returns (bytes32) {
Copy link
Contributor

@jacko125 jacko125 Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another way of approaching conversions for address type could be a library for converting address to bytes32 instead of the internal function that gets inherited by the underlying contracts (Synth.sol and Synthetix.sol).

ExternStateToken.sol

contract ExternStateToken is Owned, SelfDestructible, Proxyable {
    using SafeMath for uint;
    using SafeDecimalMath for uint;
    using addressConversion for address;

    ...
    proxy._emit(abi.encode(value), 3, TRANSFER_SIG, from.toBytes32(), to.toBytes32(), 0);
}

library addressConversions {
   function toBytes32(address input) internal pure returns (bytes32) {
      return bytes32(uint256(uint160(input)));
   }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I had considered that as FeePool needs this function as well - though is it worth managing a new library just for this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With v5 solidity it makes sense to have a library for address conversion as theres also the possible need to do conversions between address and address payable which can be included in the library , ie currently in supplySchedule.

benefits would be reducing risks of inline conversions syntax error or copy-pasting addressToBytes32() into contracts that need it.

@@ -830,7 +844,7 @@ contract FeePool is Proxyable, SelfDestructible, LimitedSetup, MixinResolver {
abi.encode(debtRatio, debtEntryIndex, feePeriodStartingDebtIndex),
2,
ISSUANCEDEBTRATIOENTRY_SIG,
bytes32(account),
bytes32(uint256(uint160(account))),
Copy link
Contributor

@jacko125 jacko125 Apr 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be re-using addressConversion library to convert address to Bytes32 for emitting the topics off the proxy.

contracts/Owned.sol Outdated Show resolved Hide resolved
Copy link
Contributor

@jacko125 jacko125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per comments

@jjgonecrypto
Copy link
Contributor Author

RFAL

Copy link
Contributor

@hav-noms hav-noms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jjgonecrypto jjgonecrypto merged commit 44d3326 into develop Apr 22, 2020
@jjgonecrypto jjgonecrypto deleted the upgrading-to-solidity-v5 branch April 23, 2020 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants