-
Notifications
You must be signed in to change notification settings - Fork 427
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
Conversation
…de explicitly abstract
…ted 0.4 file back to 0.4 compatible version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Showcase submitted comments
oraclizeAPI_0.4.sol
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
oraclizeAPI_0.4.sol
Outdated
@@ -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 |
There was a problem hiding this comment.
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
oraclizeAPI_0.4.sol
Outdated
@@ -70,7 +70,7 @@ contract usingOraclize { | |||
OraclizeI oraclize; | |||
modifier oraclizeAPI { | |||
if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) | |||
oraclize_setNetwork(); | |||
oraclize_setNetwork(networkID_auto); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
oraclizeAPI_0.4.sol
Outdated
@@ -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)); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
oraclizeAPI_0.4.sol
Outdated
|
||
bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); | ||
if (proofVerified == false) throw; | ||
require(proofVerified); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
oraclizeAPI_0.4.sol
Outdated
@@ -119,10 +119,10 @@ contract usingOraclize { | |||
return false; | |||
} | |||
|
|||
function __callback(bytes32 myid, string result) { | |||
function __callback(bytes32 myid, string result) public { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
oraclizeAPI_0.4.sol
Outdated
function oraclize_newRandomDSQuery(uint _delay, uint _nbytes, uint _customGasLimit) internal returns (bytes32){ | ||
if ((_nbytes == 0)||(_nbytes > 32)) throw; | ||
require((_nbytes != 0) && (_nbytes <= 32)); |
There was a problem hiding this comment.
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
oraclizeAPI_0.4.sol
Outdated
bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); | ||
if (proofVerified == false) throw; | ||
|
||
require(proofVerified); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert here?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as previous comment
oraclizeAPI_0.4.sol
Outdated
__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 |
There was a problem hiding this comment.
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.
oraclizeAPI_0.4.sol
Outdated
@@ -84,6 +84,10 @@ contract usingOraclize { | |||
} | |||
|
|||
function oraclize_setNetwork(uint8 networkID) internal returns(bool){ |
There was a problem hiding this comment.
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?
…to 0.4 or pre 0.4 where necessary
…rd oraclize with the remaining
…ported within the connector
There was a problem hiding this 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
oraclizeAPI_0.5.sol
Outdated
require((_proof[0] == "L") && (_proof[1] == "P") && (_proof[2] == 1)); | ||
|
||
bool proofVerified = oraclize_randomDS_proofVerify__main(_proof, _queryId, bytes(_result), oraclize_getNetworkName()); | ||
assert(proofVerified); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move back to require
oraclizeAPI_0.5.sol
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
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:
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).