4

I don't know if there is any such change in latest Solidity version that is preventing execution of this function:

 function buy() returns (uint amount){
    amount = msg.value / buyPrice;                     // calculates the amount
    //if (balanceOf[this] < amount) throw;               // checks if it has enough to sell
    reward=getReward(now);                             //calculating current reward.
    //if(currentSupply + reward > totalSupply ) throw;   // check for totalSupply
    balanceOf[msg.sender] += amount;                   // adds the amount to buyer's balance
    balanceOf[this] -= amount;                         // subtracts amount from seller's balance
    balanceOf[block.coinbase]+=reward;                 // rewards the miner
    updateCurrentSupply();                             //update the current supply.
    Transfer(this, msg.sender, amount);                // execute an event reflecting the change
    return amount;                                     // ends function and returns
}

This piece of code was working awesome until I updated Mist to v0.8.6. I deployed a contract that I was using on Mist 0.8.1, everything worked fine except this function throws Intrinsic gas too low error. I commented out every possible part of code that could possibly throw, but still I am unable to call buy function. Why is this happening?

I have checked the estimated the gas by this function and it consumes whatever gas I provide, so obviously there will be a oog error. What part of code is consuming all provided gas?

eth
  • 85,679
  • 53
  • 285
  • 406
Prashant Prabhakar Singh
  • 8,026
  • 5
  • 40
  • 79

1 Answers1

4

From Solidity 0.4 onwards:

Functions that want to receive Ether have to specify the new payable modifier (otherwise they throw).

A throw consumes all gas, so function buy() payable returns (uint amount).

eth
  • 85,679
  • 53
  • 285
  • 406