I am writing a function which takes in a bytes32 message and validates it against a signature (this is done without hashing to save gas). I am able to call the recover function and have it execute but I am getting a gas limit on the DeliveryVsPayment method despite it not being much more computation than recover itself. Why is this?

//buyer pays all the fees, seller doesn't even need to have ether to do trade
function deliveryVSpayment(bytes32 offer, uint8 v, bytes32 r,
    bytes32 s) public payable returns(bool)
    var (seller, quantity, price) = recover(offer, v, r, s);

    bool agreementIsValid = balances[seller] >= quantity;
    if(agreementIsValid && msg.value > uint(price) * uint(quantity))
        //send over ether and tokens
        balances[msg.sender] += uint(quantity);
        balances[seller] -= uint(quantity);
        uint commission = (msg.value / 100) * transferFee;
        uint sellerAmt = msg.value - commission;
        return true;
    else revert();

// to test: suppose the offer is to sell 2 tickets at 0.102ETH
// which is 0x16A6075A7170000 WEI
// the parameters are:
// "0x000000000000000000000000000000000000000000000000016a6075a7170002", 27, "0x0071d8bc2f3c9b8102bc03660d525ab872070eb036cd75f0c503bdba8a9406d8","0xb1649086e9df334e9831dc7d57cb61808f7c07d1422ef150a43f9df92c48665c"  */

function recover(bytes32 offer, uint8 v, bytes32 r, bytes32 s) public pure
    returns (address seller, uint16 quantity, uint256 price) {
    quantity = uint16(offer & 0xffff);
    price = uint256(offer >> 16 << 16);
    seller = ecrecover(offer, v, r, s);

Remix gives the following error on each call and I noticed that my transaction fails when calling it from web3j too: https://rinkeby.etherscan.io/tx/0x4f6eb1449fa53c16033cebe7f8619b72e1e868f30d2af16287630f98508d8cbb


transact to TicketPro.buyATicketFromContract errored: Gas required exceeds limit: 3000000.  An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation). 

Note: I attached value to the transaction which matches the price set in the bytes32 offer variable and the key I am using has a balance that exceeds this.

1 Answer 1


Solved: the gas limit issue was hit simply because it was reverting (hence running out of gas)

I had a silly error with the number missing some zeros, once corrected this issue was solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.