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

Targeting solidity compiler v0.4.18 and updated to silence warnings #23

Merged
merged 22 commits into from
Nov 30, 2017

Conversation

AdamJLemmon
Copy link
Contributor

@AdamJLemmon AdamJLemmon commented Nov 20, 2017

Updated method visibility and mutability(public, pure, view), replaced sha3 with keccak256, all throws updated to requires and unused variables removed or "used".

Note the initial commit seems to be an issue with atom new line chars where several lines were removed and re-added but shown as diffs.

Single warning remains:

oraclizeAPI_0.4.sol:129:5: Warning: Function state mutability can be restricted to pure
    function __callback(bytes32 myid, string result, bytes proof) public {

Would need to update state to silence this and cannot add the pure modifier as inheriting contracts can not change the mutability modifier and thus would be bound to pure.

Have tested all examples in the browser solidity fork as well as the nested and computation examples from the test query page. Also deployed to kovan and tested the randomDS(https://github.com/oraclize/ethereum-examples/blob/master/solidity/random-datasource/randomExample.sol).

@AdamJLemmon AdamJLemmon changed the title Tagretting solidity compiler v0.4.18 and updated to silence warnings Tagreting solidity compiler v0.4.18 and updated to silence warnings Nov 20, 2017
@AdamJLemmon AdamJLemmon changed the title Tagreting solidity compiler v0.4.18 and updated to silence warnings Targeting solidity compiler v0.4.18 and updated to silence warnings Nov 20, 2017
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.

Showcase submitted comments

@@ -126,7 +126,9 @@ contract usingOraclize {
function __callback(bytes32 myid, string result) public {
__callback(myid, result, new bytes(0));
}
function __callback(bytes32 myid, string result, bytes proof) public;
function __callback(bytes32 myid, string result, bytes proof) public {
myid; result; proof; // Silence compiler warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

change to

return;
myid; result; proof; // Silence compiler warnings

so it never needlessly actually adds them to the stack, but just satisfies the compiler?

Copy link
Contributor

@marcogiglio marcogiglio Nov 29, 2017

Choose a reason for hiding this comment

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

Strange that the compiler doesn't complain about an empty statement. Do you think it won't be changed in the future?

@@ -28,7 +28,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

pragma solidity ^0.4.0;//please import oraclizeAPI_pre0.4.sol when solidity < 0.4.0
pragma solidity ^0.4.18;//please import oraclizeAPI_pre0.4.sol when solidity < 0.4.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Update comment message appropriately:

//please import oraclizeAPI_0.4.sol when solidity < 0.4.18

EDIT: Ignore, this comment is based on the erroneous assumption that this contract would supplement the current one and not replace it. However, might still update it saying to change the compiler version to the needed 0.4.x one but that the api is targeted at 0.4.18

@@ -70,7 +70,7 @@ contract usingOraclize {
OraclizeI oraclize;
modifier oraclizeAPI {
if((address(OAR)==0)||(getCodeSize(address(OAR))==0))
oraclize_setNetwork();
oraclize_setNetwork(networkID_auto);
Copy link
Contributor

Choose a reason for hiding this comment

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

API by default should not use the dummy oraclize_setNetwork(uint8) function, but the direct oraclize_setNetwork() function for efficiency.

Copy link
Contributor

@marcogiglio marcogiglio Nov 29, 2017

Choose a reason for hiding this comment

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

I agree with @D-Nice. It's cheaper gas wise

@@ -763,7 +763,7 @@ contract usingOraclize {
}

function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){
if ((_nbytes == 0)||(_nbytes > 32)) throw;
require((_nbytes != 0) && (_nbytes <= 32));
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe _nbytes > 0 check is more appropriate for first condition?

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, more for clarity than for a security need. Since _nbytes is uint, sending a negative value would simply overflow the variable and that would be catched by the second conditions.


bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName());
if (proofVerified == false) throw;
require(proofVerified);
Copy link
Contributor

Choose a reason for hiding this comment

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

would an assert be more appropriate here?

Copy link
Contributor

Choose a reason for hiding this comment

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

If you read here, it is actually the opposite: the require-style exception uses the new revert opcode, while the assert uses the throw opcode. So, it is should be require.

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I understand, hence why I'm recommending assert. Otherwise, Oraclize can reward itself for providing wrong queries, with proofs that purposefully fail, taking leftover gas as profit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but it could be useful for offchain payments and gas refunds.

@@ -119,10 +119,10 @@ contract usingOraclize {
return false;
}

function __callback(bytes32 myid, string result) {
function __callback(bytes32 myid, string result) public {
Copy link
Contributor

Choose a reason for hiding this comment

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

should the default methods implement check to ensure msg.sender is Oraclize cbAddress??? Or is it expected to fallback/be overriden.

Copy link
Contributor

@marcogiglio marcogiglio Nov 29, 2017

Choose a reason for hiding this comment

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

That extra-check would slightly increase the gas usage on deployment for every contract, as most of them only deploy the _callback with proof. And I also believe it would be redundant, as most of them will have that check any way in the implemented callback. So I believe it is better to leave it as it is.

function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){
if ((_nbytes == 0)||(_nbytes > 32)) throw;
require((_nbytes != 0) && (_nbytes <= 32));
Copy link
Contributor

Choose a reason for hiding this comment

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

For clarity, greater than check replacement on first condition?

_nbytes > 0

bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName());
if (proofVerified == false) throw;

require(proofVerified);
Copy link
Contributor

Choose a reason for hiding this comment

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

assert here?

Copy link
Contributor

Choose a reason for hiding this comment

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

reasoning is, to not reward Oraclize with leftover gas on a failed proof.

Copy link
Contributor

@marcogiglio marcogiglio Nov 29, 2017

Choose a reason for hiding this comment

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

Same as previous comment

__callback(myid, result, new bytes(0));
}
function __callback(bytes32 myid, string result, bytes proof) {
function __callback(bytes32 myid, string result, bytes proof) public {
myid; result; proof; // Silence compiler warnings
Copy link
Contributor

Choose a reason for hiding this comment

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

prepend return, before pushing args to stack. Although it should be overridden and not used in general.

@@ -84,6 +84,10 @@ contract usingOraclize {
}

function oraclize_setNetwork(uint8 networkID) 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.

Don't use this dummy function now directly in the contract here, replace with a direct call to oraclize_setNetwork() if @marcogiglio @bertani can confirm no backwards compatibility breaks there?

Copy link
Contributor

@marcogiglio marcogiglio left a comment

Choose a reason for hiding this comment

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

Only things I see that needs to be changed is to move back to require, everything else LGMT

require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1));

bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName());
assert(proofVerified);
Copy link
Contributor

Choose a reason for hiding this comment

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

Move back to require

@@ -853,7 +853,7 @@ contract usingOraclize {
require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1));

bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName());
assert(proofVerified);
require(proofVerified);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marcogiglio @D-Nice Reverted back to require from assert.

@AdamJLemmon AdamJLemmon merged commit 338a56b into master Nov 30, 2017
@D-Nice D-Nice deleted the AL_solc4.18_silence_warnings branch July 2, 2019 21:22
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.

3 participants