1

I encountered keccal256 error in binance smart chain based coin. This error occurred in a token generated with cointool.app. I came across this example. how to solve this error? https://blog.soliditylang.org/2021/03/23/keccak-optimizer-bug/ thank you for your help.

function isContract(address account) internal view returns (bool) { // According to EIP-1052, 0x0 is the value returned for not-yet created accounts // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. keccak256('') bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); }

4
  • Can you give more details about the error? What's the contract source? The solidity bug applies when you used assembly to compute keccak256, if the contract didn't use assembly it wouldn't apply to it.
    – Ismael
    Sep 8, 2021 at 5:48
  • function isContract(address account) internal view returns (bool) { 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned // for accounts without code, i.e. keccak256('') bytes32 codehash; bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470; // solhint-disable-next-line no-inline-assembly assembly { codehash := extcodehash(account) } return (codehash != accountHash && codehash != 0x0); } Sep 8, 2021 at 10:13
  • You can format code by surrounding it with ``` (three backticks), before and after the code.
    – Ismael
    Sep 8, 2021 at 15:39
  • The function doesn't use keccak from assembly so it shouldn't be affected by solidity bug. In any case if some other part is affected by it the only solution is to deploy a new version of the contracts. Did you try deploying a new version in a testnet to validate if it fixes it? If compiling with solc 0.8.3 doesn't fix it the problem is somewhere else.
    – Ismael
    Sep 8, 2021 at 15:43

1 Answer 1

0

As mentioned in the blog post, you would need to use solidity version 0.8.3 and above to avoid this bug. So you would need to deploy a new coin contract, as the previous one can't be altered as it's immutable on the blockchain.

Your Answer

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

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