0

WE Had Create A Dapp Like POWHD, we Already Deployed It And Some Of Transactions Are Already Done well. But After Some Time The issue I'm encountering with my real contract (Dapp) is that trying to send any amount of ETH produces this warning: "Transaction Error. Exception thrown in contract code. Gas limit set dangerously high. Approving every transaction is likely to fail."

Can anyone explain why I am getting this error? I can't understand why an error is producing when someone sends an amount of ETH every time. “Contract 0x25a06d4e1f804ce62cf11b091180a5c84980d93a”
Warning! Error encountered during contract execution [Out of gas] For example failed Tra.Hash : https://etherscan.io/tx/0x8da0cc8887aaec2203a0e78f8e56c31482d2c3b5637f2456ec07cc6a8f2e8d1b Smart contract (TRS) https://etherscan.io/address/0x25a06d4e1f804ce62cf11b091180a5c84980d93a

1

The contract has a denial of service vulnerability

For every purchase you have to search linearly if the address is already in contractTokenHolderAddresses_. If you have too many users it will cause an out of gas error. A solution is to use a mapping from address to bool and set to true users who purchase tokens.

function purchaseTokens(uint256 _incomingEthereum, address _referredBy)
    internal
    returns(uint256)
{
    // ------------8<--------------

    bool isFound=false;

    for (uint k=0; k<contractTokenHolderAddresses_.length; k++) {
        if (contractTokenHolderAddresses_[k] ==_customerAddress) {
            isFound=true;
            break;
        }
    }

    if (!isFound) {
        //increment address to keep track of no of users in smartcontract
        contractAddresses_+=1;  
        contractTokenHolderAddresses_.push(_customerAddress);
    }

    // ------------8<--------------
  • Thanks for your Answer but is it possible to update after deploying real contract ? – sunny Dev Apr 21 at 7:30
  • Is not possible, the only solution in your case is to increase the gas limit in the transaction. However, this will get worse as more people get into your game. You may consider to deploy it again, there are many things in the code that could be improved. If you have a team, ask each one to read the full code. – Jaime Apr 21 at 14:52
  • @sunnyDev No, it was not possible to update contracts until recent Constantinople fork. They have to be created in a different way to allow upgrades. Unfortunately there's not much you can do, your contract lacks a halt mechanism, the only thing that seems to work is withdraw. – Ismael Apr 21 at 16:46
0

In case it helps amplify Ismael's answer. An unbounded iteration is an anti-western because it doesn't scale.

The fatal flaw is warned about here: https://blog.b9lab.com/getting-loopy-with-solidity-1d51794622ad

You need a storage pattern that will ensure consistent gas cost at any scale, a.k.a. O(1) complexity. A general-purpose solution is described here: https://medium.com/robhitchens/solidity-crud-part-1-824ffa69509a

An audit would have caught that: https://blog.b9lab.com/https-blog-b9lab-com-saved-by-audits-bc64ea65446c

You can't repair the contract so you will have to consider replacement and data migration.

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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