-
-
Notifications
You must be signed in to change notification settings - Fork 824
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[codegen]: fix assertions for certain precompiles (#4451)
this commit fixes a flaw in code generation for certain precompiles. specifically, some calls to the ecrecover (0x01) and identity (0x04) precompiles were not checked for success. in 93a9579, the assert for memory copying calls to the identity precompile was optimized out; the reasoning being that if the identity precompile fails due to OOG, the contract would also likely fail with OOG. however, due to the 63/64ths rule, there are cases where just enough gas was supplied to the current call context so that the subcall to the precompile could fail with OOG, but the contract has enough gas to continue execution after it shouldn't (which is undefined behavior) and then successfully return out of the call context. (note that even prior to 93a9579, some calls to the identity precompile did not check the success flag. cf. commit cf03d27. the call to ecrecover was unchecked since inception - db44cde). note also that since cancun, memory copies are implemented using the `mcopy` instruction, so the bug as it pertains to the identity precompile only affects pre-cancun compilation targets. this commit fixes the flaw by converting the relevant unchecked calls to checked calls. it also adds tests that trigger the behavior by running the call, and then performing the exact same call again but providing `gas_used` back to the contract, which is the minimum amount of gas for the call to the contract to finish execution. the specific amount of gas left at the point of the subcall is small enough to cause the subcall to fail (and the check around the subcall success to revert, which is what is tested for in the new tests). in these tests, it also adds a static check that the IR is well-formed (that all relevant calls to precompiles are appropriately checked). references: - GHSA-vgf2-gvx8-xwc3
- Loading branch information
1 parent
d7f50df
commit 7136eab
Showing
7 changed files
with
257 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters