hats-finance / Fenix-Finance-0x83dbe5aa378f3ce160ed084daf85f621289fb92f

0 stars 0 forks source link

Incorrect `POOL_INIT_CODE_HASH` will result in computation of incorrect pool address #54

Open hats-bug-reporter[bot] opened 7 months ago

hats-bug-reporter[bot] commented 7 months ago

Github username: @0xRizwan Twitter username: 0xRizwann Submission hash (on-chain): 0x1f6fc52e0c7a280e723747101dd4de7225f0d10b1540c6f20fe6d766387f1216 Severity: high

Description: Description\

AlgebraFactory.sol is used to deploy pools and its plugins. The POOL_INIT_CODE_HASH used in AlgebraFactory.sol is given as below,

  bytes32 public constant POOL_INIT_CODE_HASH = 0x0a0bfc292c9afb85f925683c4bc7f47c146b36460a4d81b8e661ff2b4fca3b12;

POOL_INIT_CODE_HASH is used for computation of pool address.


  function computePoolAddress(address token0, address token1) public view override returns (address pool) {
    pool = address(uint160(uint256(keccak256(abi.encodePacked(hex'ff', poolDeployer, keccak256(abi.encode(token0, token1)), POOL_INIT_CODE_HASH)))));
  }

and this further used in creation of pool in createPool()

      defaultPlugin = defaultPluginFactory.createPlugin(computePoolAddress(token0, token1), token0, token1);

The issue here is, POOL_INIT_CODE_HASH used is incorrect, Therefore, the pool address calculated will be wrong.

AlgebraFactory.sol uses Algebra Integral 1.0

/// @dev Version: Algebra Integral 1.0

Algebra Integral 1.0 has used below POOL_INIT_CODE_HASH. This can be checked here

  bytes32 public constant POOL_INIT_CODE_HASH = 0xf96d2474815c32e070cd63233f06af5413efc5dcb430aee4ff18cc29007c562d;

Therefore, by using above correct code hash, the pool address will computed correctly. As the init code hash changed, contract bytecode has been change, the init hash will be different. This will cause a total bricking of all major functionality.

Recommendations\

Correct the POOL_INIT_CODE_HASH in AlgebraFactory.sol as used for Algebra Integral 1.0

BohdanHrytsak commented 7 months ago

Thank you for the submission.

We use our own implementation of AlgebraPool, which is minimally different from the original, but it still results in a new INIT_CODE_HASH at the factory, so this value is different from the value in Algebra Integral 1.0