Skip to content
This repository has been archived by the owner on Apr 28, 2024. It is now read-only.

shogoki - Protocol is not usable & possible lock of funds on zksync because of wrong address computation #25

Closed
sherlock-admin opened this issue Oct 23, 2023 · 0 comments
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Oct 23, 2023

shogoki

medium

Protocol is not usable & possible lock of funds on zksync because of wrong address computation

Summary

The Wagmi Leverage Protocol is supposed to be deployed on many chains, including the zksync Era chain.
On multiple occurences the address of the UniswapV3 pool to use is computed by using the deterministic way the create2 opcode for EVM works, which is different for zkSync ERA.

This results in the protocol not being correctly usable and the possibility for funds to be locked.

Vulnerability Detail

The contracts interact with UniswapV3 pools several times. The address of the pool is always computed by the contract using the UNDERLYING_V3_POOL_INIT_CODE_HASH the UNDERLYING_V3_FACTORY_ADDRESS and the salt which is the hash of the tokens and the fee.

This works, as the UniswapV3 pools are created by the Factory using the create2 opcode, which gives us an deterministic address based on these parameters. (see here

However, the address derivation works different on the zkSync Era chain, as they are stating in their docs.

export function create2Address(sender: Address, bytecodeHash: BytesLike, salt: BytesLike, input: BytesLike) {
  const prefix = ethers.utils.keccak256(ethers.utils.toUtf8Bytes("zksyncCreate2"));
  const inputHash = ethers.utils.keccak256(input);
  const addressBytes = ethers.utils.keccak256(ethers.utils.concat([prefix, ethers.utils.zeroPad(sender, 32), salt, bytecodeHash, inputHash])).slice(26);
  return ethers.utils.getAddress(addressBytes);
}

This will result in the computed address inside the contract to be wrong, which make any calls to these going to be reverted, or giving unexpected results.

As there is a possibility for the borrow function to go work fine, as the computed address will not be used, there is a potential for getting funds into the Vault. However, these would be locked forever, as every possible code path of the repay function is relying on the computed address of the UniswapV3 pool.

Impact

  • Protocol is not usable on zkSync Era network
  • Funds could be locked.

Code Snippet

https://github.com/sherlock-audit/2023-10-real-wagmi/blob/main/wagmi-leverage/contracts/abstract/ApproveSwapAndPay.sol#L211-L213C16

https://github.com/sherlock-audit/2023-10-real-wagmi/blob/main/wagmi-leverage/contracts/abstract/ApproveSwapAndPay.sol#L271C4-L291C6

Tool used

Manual Review

Recommendation

As zkEVM differs in some points from the EVM, i would consider writing a slightly adjusted version of the contract for zkEVM, in regards to the differences mentioned in their docs

Duplicate of #104

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Oct 26, 2023
@sherlock-admin sherlock-admin changed the title Precise Ceramic Donkey - Protocol is not usable & possible lock of funds on zksync because of wrong address computation shogoki - Protocol is not usable & possible lock of funds on zksync because of wrong address computation Oct 30, 2023
@sherlock-admin sherlock-admin added the Reward A payout will be made for this issue label Oct 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label Medium A valid Medium severity issue Reward A payout will be made for this issue
Projects
None yet
Development

No branches or pull requests

1 participant