Submitted by Zubat, also found by RadiantLabs
When certain precompiles are invoked in an L2 transaction, the OP fault proof program substitutes their logic with type 6 preimage oracle queries. Reviewing the op-program code shows that the ecrecover (0x1), bn256Pairing (0x8), and kzgPointEvaluation (0xa) precompile addresses are currently part of this precompile accelerators system. For this system to function correctly, a precompile call on L2 must always be reproducible on L1 via the loadPrecompilePreimagePart() function in the PreimageOracle. This is currently not guaranteed in at least one scenario on OP mainnet.
Specifically, note that the bn256Pairing precompile has an unbounded gas cost of 34_000 * k + 45_000, where k is the input size divided by 192. This means that a user can call the bn256Pairing precompile on L2 with an input that uses nearly the entire L2 block gas limit. Currently, the block gas limit on both Ethereum mainnet and OP mainnet is 30_000_000. Since the block gas limits are the same, every precompile call on L2 is theoretically reproducible on L1 in isolation. However, since the loadPrecompilePreimagePart() function has its own overhead gas costs, it can be shown that some L2 precompile calls can be impossible to reproduce for the purposes of the PreimageOracle.
For example, consider a scenario where the following smart contract is successfully called on L2:
Since the input is 165_504 bytes, the cost of calling the bn256Pairing precompile is 29_353_000 gas. However, since EIP-150 limits the amount of gas the PreimageOracle can forward to 63/64 of its available gas, the loadPrecompilePreimagePart() function would require 29_353_000 * 64 / 63 = 29_818_920 gas in order to reproduce this precompile call successfully. There are two options for a user to attempt to meet this threshold:
As a result, this L2 precompile transaction will lead to a preimage oracle query that is impossible to satisfy on L1. This would make the corresponding step() impossible to execute, which would prevent invalid state transitions from being countered.
The following test can be added to op-e2e/faultproofs/output_cannon_test.go:
After running go test ./faultproofs -run TestImpossiblePrecompileCallBug -v -timeout=60m > test_output.txt, the output can be inspected as follows:
This shows that the L2 precompile call succeeded, and the challenger failed to load the preimage for the relevant execution step. In this case, the error is due to a transaction size limit, which is another limitation in addition to the gas issues described above.
Also note that before running the test, the following change is useful for op-challenger/game/fault/preimages/split.go to ensure it differentiates large precompile calls from large keccak256 preimages:
The op-e2e test suite.
If possible, the accelerated precompiles system should avoid precompiles that have dynamic gas costs. Although this would imply a larger execution trace for precompile calls that would otherwise be supported, this seems to be the safest option in the long term. This is especially true if the block gas limits on L2 are ever changed to exceed the L1 block gas limit.
ajsutton (Optimism) confirmed via duplicate Issue #28
Inphi (Optimism) commented:
obront (judge) commented:
Inphi (Optimism) commented:
