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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Solc 0.5 #67

Merged
merged 15 commits into from
Nov 30, 2018
Merged

Update to Solc 0.5 #67

merged 15 commits into from
Nov 30, 2018

Conversation

gskapka
Copy link
Collaborator

@gskapka gskapka commented Nov 26, 2018

Solc 0.5.0 Version of the API

Here it is, the API upgraded to the latest Solidity compiler, and (hopefully) following all the best practices. Rather than simply getting it to compile, many other changes have been made and so hence the need for a thorough review. Amongst those changes:

  • Added stuff to make it compile (a million memory keywords &c.)
  • More explicit castings (which broke stuff - see later) between types
  • Adding a safe version of parseInt() (original remains incase anyone using its behaviour)
  • Moved all global variables to the top of the contract
  • Moved all modifiers together
  • Standardized comment styles (/* ... */ for multilines instead of multiple //'s)
  • Standardized grammar in comments
  • Standardized white space between lines
  • Standardized variable naming (the few examples of snake_case are now camelCased)
  • Standardized use of whitespace between function declaration parens. vs. if/while/for conditionals
  • Standardized the use of whitespace between closing parens. & {s
  • Standardized the use of underscores before parameter names
  • Fix the failing RandomDS proof (which I broke during the above)

Notes:

Re which latter bullet point: It turns out that with the new recasting rules we must first cast to types of the same size. So to go from bytes(1) to uint we first need to go via either uint8 or bytes32:

uint256(bytes32(bytes1(...)));
// or
uint256(uint8(bytes1(...)));

The two casts pad differently hence the new explicitness ruling. As such, I broke (and then fixed) the proof verification thusly:

api-break

To Do

@D-Nice & @riccardopersiani please can you go over this PR with a fine tooth comb and make sure I haven't goofed anything? Also tell me if any of the above listed changes are a step too far/pointless/terrible/should be burnt with fire &c., &c.

Also, I have a private repo elsewhere with some (unpolished but passing) tests for some of the parsing helpers we offer in this API, plus all the truffle examples in the ethereum-examples repo have been updated to als use this API and all tests therein are also passing.
So it should be all good w/r/t it working, now it's just a case of arguing over the changes I've made.

@D-Nice
Copy link
Contributor

D-Nice commented Nov 27, 2018

shall we also decide on a standard as to whether to return anonymous or named variables?

@gskapka
Copy link
Collaborator Author

gskapka commented Nov 27, 2018

Easy question for me - named variables everytime (unless we're talking point-free - but that's a different & more fun kettle of fish!). That whole:

naming is hard

thing is dumb. Naming is explicit and useful and enlightening.

Copy link
Contributor

@D-Nice D-Nice left a comment

Choose a reason for hiding this comment

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

Overall changes look good and definitely increased quality of code.

Can you confirm these have been run through your ethereum-examples testing suite @gskapka ?

Some changes recommended, clarifications, and points needing discussion, and acceptable for merge thereafter. Some points need @bertani feedback.

oraclizeAPI_0.5.sol Show resolved Hide resolved
oraclizeAPI_0.5.sol Outdated Show resolved Hide resolved
oraclizeAPI_0.5.sol Show resolved Hide resolved
oraclizeAPI_0.5.sol Outdated Show resolved Hide resolved
struct buffer {
bytes buf;
uint capacity;
}

function init(buffer memory buf, uint _capacity) internal pure {
function init(buffer memory _buf, uint _capacity) internal pure {
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 this as well. It may be worth actually seeing about pushing these updates towards: https://github.com/smartcontractkit/solidity-cborutils

So we can stay consistent with that repo. Additonally may be useful to ensure there haven't been some bugfixes to that cbor library since?

Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the reason Nick did not go this route, is the functions are pure anyways, and it's a library, so they won't themselves have any side effects(at least from a state perspective, it will affect memory in certain functions).

oraclizeAPI_0.5.sol Show resolved Hide resolved
mapping(bytes32=>bool) oraclize_randomDS_sessionKeysHashVerified;

function verifySig(bytes32 tosignh, bytes dersig, bytes pubkey) internal returns (bool){
function verifySig(bytes32 _tosignh, bytes memory _dersig, bytes memory _pubkey) internal returns (bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

safe to set to view or pure even?

Copy link
Collaborator Author

@gskapka gskapka Nov 28, 2018

Choose a reason for hiding this comment

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

Ibid. re compiler warnings. Plus gives bonus extra compiler warnings about needing to set either payable or non-payable on it. Sigh.

}
}

function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes proof, uint sig2offset) internal returns (bool) {
function oraclize_randomDS_proofVerify__sessionKeyValidity(bytes memory _proof, uint _sig2offset) internal returns (bool) {
Copy link
Contributor

Choose a reason for hiding this comment

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

could be view or pure again?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ibid. re compiler warnings.

The following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
Duplicate Solidity's ecrecover, but catching the CALL return value
*/
function safer_ecrecover(bytes32 _hash, uint8 _v, bytes32 _r, bytes32 _s) internal returns (bool, address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

pure?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ibid. re compiler warnings & whole slew of new ones re payable etc.

/*
The following function has been written by Alex Beregszaszi (@axic), use it under the terms of the MIT license
*/
function ecrecovery(bytes32 _hash, bytes memory _sig) internal returns (bool, address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

pure

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ibid. re all the other ibids.

@gskapka
Copy link
Collaborator Author

gskapka commented Nov 28, 2018

Update:

Okay so I've done anything from the above review that I can & pushed it. I've also compiled anything I couldn't do into this one post to make it easier to see & address.

Done:

✔️ Naming return params (and adding underscores to go along with current practices)
✔️ Fixing the license typo.
✔️ Removing white space from string [] type declarations.

I can confirm that all tests are passing on all examples that have test-suites per my tool on gitlab using this current iteration of the API.


Stuff that needs discussing/addressing:

📟 Paging @bertani & @D-Nice, whose relevance to issues at hand are marked after the issues:

  • Do we update the copyright information? (@bertani)
     
  • Should getPrice become view? (@bertani, @D-Nice)
     
  • Do we remove the coupon function? (@bertani)
     
  • Do we drop the safeMemoryCleaner function? (@bertani)
     
  • Do we revert with a message on finding an unexpectedly high price in a query? (@bertani)
     
  • Do we use view, pure &c., even where it results in a lot more compiler warnings? (@bertani, @D-Nice)
     
  • Do you hate my compulsion & aesthetic driven re-ordering of listed variables into length order enough to make me revert it? (@D-Nice)

@gskapka
Copy link
Collaborator Author

gskapka commented Nov 28, 2018

Responses to above from @bertani

  • Re copyright: No, it's fine as is.
     
  • Re getPrice becoming view: Whatever keeps compatability with the current connector.
     
  • Re coupon: Can be removed.
     
  • Re safeMemoryCleaner: Since @D-Nice implemented it, if it's no longer patching whatever it patched it can be dropped.
     
  • Re revert, if we didn't throw in the first place, the return value was probably there for a reason so it's probably best to keep the current behaviour.
     
  • Re compiler warnings: if they don't change behaviour, it'd be best to minimise compiler warnings at the expense of being explicit with the visibility specifiers.

Next:

⚖️ Just need you to weigh in now @D-Nice please!

@D-Nice
Copy link
Contributor

D-Nice commented Nov 30, 2018

ok, based on those replies, let's remove coupon. Also, based on our earlier discussion, and me diving into safeMemoryCleaner, I think it's best we still leave it in, because as mentioned, it can be useful for any other assembly that works on memory, but doesn't necessarily zero it out, so the safeMemoryCleaner can be re-used there.

@gskapka
Copy link
Collaborator Author

gskapka commented Nov 30, 2018

Done & done.

@axic
Copy link

axic commented Nov 30, 2018

Oh wow, this is great! :)

@D-Nice D-Nice deleted the solc-0.5 branch July 2, 2019 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants