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

oraclize.getPrice() returns with invalid opcode when oraclize_setProof() is not set #12

Closed
szerintedmi opened this issue May 23, 2017 · 2 comments

Comments

@szerintedmi
Copy link

The documentation says the default is proofType_NONE
However when I call oraclize.getPrice() from browser-solidity then it returns with "VM Exception: invalid opcode" when I don't have proof set.
If I add oraclize_setProof(proofType_NONE); to constructor then it works fine.
Solidity version: 0.4.12-nightly.2017.5.4+commit.025b32d9.Emscripten.clang
Code to reproduce:

/*
  Oraclize.it decrypt datasource test
*/

pragma solidity ^0.4.0;
import "github.com/oraclize/ethereum-api/oraclizeAPI.sol";

contract CryptTest is usingOraclize {
    
    string public callBackResult;
    bytes32 public qId;
    bytes32 public resId;
    
    event newOraclizeQuery(string description);
    event newResult(string result);
    
    function CryptTest() payable {
        // oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS);
       // setProof not called causing invalid opcode for getDecryptPrice 
      // but If you uncomment the following line then it works
        // oraclize_setProof(proofType_NONE); 
    }

    function __callback(bytes32 myid, string result) {
        if (msg.sender != oraclize_cbAddress()) throw;
        resId = myid;
        callBackResult = result;
        newResult(callBackResult);
    }
    
    function getDecryptPrice() constant returns (uint){
        return oraclize.getPrice("decrypt") ;
    }
    
    function decrypt(string inp) payable {
        uint requiredBal = getDecryptPrice() ;
        if ( requiredBal> this.balance) {
            newOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee" );
        } else {
            newOraclizeQuery("Oraclize query was sent, standing by for the answer..");
            qId = oraclize_query( "decrypt", inp);
        }
    }
} 

Just a minor annoyance, documenting if someone else happens to bump into it.

@bertani
Copy link
Contributor

bertani commented May 23, 2017

Hello @szerintedmi , the problem is caused by the fact that you are using oraclize.getPrice instead of oraclize_getPrice.
The former is acting at a lower level and gives for granted that the OraclizeAddressResolver has already been detected by the contract (auto network detection), which is not the case in your contract, hence causing it to throw! The reason why it works after an oraclize_setProof is that any oraclize_-prefixed function is higher level and ensures internally that the OraclizeAddressResolver has been correctly resolved already.
oraclize_setProof is completely optional, but I would suggest to always go with oraclize_* functions instead of oraclize.* ones.

I hope this helps!

@szerintedmi
Copy link
Author

Indeed, that helped ! I can't find anymore from which example I got that code line from. It's likely wasn't any of yours :)

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

No branches or pull requests

2 participants