sherlock-audit / 2024-05-pooltogether-judging

8 stars 4 forks source link

elhaj - Hardcoded Gas for Hooks May Prevent Winners from Receiving Prizes Due to Insufficiency on Different Chains #81

Closed sherlock-admin3 closed 2 months ago

sherlock-admin3 commented 3 months ago

elhaj

medium

Hardcoded Gas for Hooks May Prevent Winners from Receiving Prizes Due to Insufficiency on Different Chains

Summary

sherlock-admin4 commented 2 months ago

1 comment(s) were left on this issue during the judging contest.

infect3d commented:

on L2 gas is made of L1 gas and L2 gas__ internal calls only consume the L1 gas i.e opcodes cost

trmid commented 2 months ago

The zkSync doc link provided in the issue appears to be outdated or broken and does not have any info on the topic. Is there some updated information on this?

nevillehuang commented 2 months ago

Request poc

sherlock-admin4 commented 2 months ago

PoC requested from @elhajin

Requests remaining: 2

elhajin commented 2 months ago

on L2 gas is made of L1 gas and L2 gas__ internal calls only consume the L1 gas i.e opcodes cost

Here's a quote from zkSync docs about that:

Do not rely on EVM gas logic ZKsync VM has a different set of computational trade-offs compared to the standard computational model. In practice, this means that the price for opcodes is different to Ethereum. Also, zkEVM contains a different set of opcodes under the hood, and so the “gas” metric of the same set of operations may be different on ZKsync Era and on Ethereum.

For Arbitrum, it's a bit complicated. Gas is calculated as a function of the actual gas consumed on L2 and the L1 calldata cost, which is effectively an L2 view of the L1 gas price. Please refer to the Arbitrum docs for more information on how gas is estimated.

trmid commented 2 months ago

In the Arbitrum doc provided, it is stated that:

It works the same as Ethereum gas, in the sense that every EVM instruction costs the same amount of gas that it would on Ethereum.

The gas price is changed dynamically to reflect the L1 and L2 fees, but the gas used remains EVM equivalent.

The PoC listed in the issue does not fail as described. Adding the fork in the test shown reverts for unrelated reasons, and forking the Arbitrum One network in the setup function in Claimable.t.sol results in no errors whatsoever for the testClaimPrize_bothHooks test. This aligns with live results we see on the current Arbitrum One deployment, with hooks running with similar gas used as on Optimism and Base.

As for ZKSync, the main difference from Ethereum gas computation appears to be the gasPerPubdata field which is set by the caller when sending a tx. This is then added to the gas costs based on the resulting state changes and logs from the tx execution. The gas used by opcodes appears to be very similar with some minor changes. There seems to be no indication that 150k gas would be insufficient for the zkSync execution environment.

nevillehuang commented 2 months ago

@elhajin @trmid Seems like per pooltogether's minting logic, the gas spent will not exceed 150_000 gas on arbitrum But this is unconfirmed based on zksync's computation.

nevillehuang commented 2 months ago

@elhajin Is there any additional information you can provide to prove gas computations can exceed 150_000 on zksync?

elhajin commented 2 months ago

My argument is based on the docs that I quote and for me it's pretty clear that a hardcoded 150k gas can be not enough.and it's explicitly mentioned to not hardcode any gas because zksync have an evolving fee model Screenshot_2024-06-16-10-12-19-65_40deb401b9ffe8e1df2f1cc5ba480b12.jpg

nevillehuang commented 2 months ago

@elhajin If there is no conclusive evidence that gas will exceed 150_000 on zksync if contracts are deployed as is, I would have to note this as a future integration issue that is OOS:

Future issues: Issues that result out of a future integration/implementation that was not mentioned in the docs/README or because of a future change in the code (as a fix to another issue) are not valid issues.