Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Compiler/CompilationModel/DynamicData.lean
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ def panicError0x11HelperName : String :=
def panicError0x12HelperName : String :=
"panic_error_0x12"

def panicErrorHelper (helperName : String) (code : Nat) : YulStmt :=
YulStmt.funcDef helperName [] [] [
/-- ABI payload for Solidity's built-in `Panic(uint256)` error.

The payload is exactly 36 bytes:
4-byte selector `0x4e487b71` followed by one ABI word containing `code`. -/
def solidityPanicPayload (code : Nat) : List YulStmt :=
[
YulStmt.expr (YulExpr.call "mstore" [
YulExpr.lit 0,
YulExpr.call "shl" [YulExpr.lit 224, YulExpr.hex 0x4e487b71]
Expand All @@ -127,6 +131,9 @@ def panicErrorHelper (helperName : String) (code : Nat) : YulStmt :=
YulStmt.expr (YulExpr.call "revert" [YulExpr.lit 0, YulExpr.lit 36])
]

def panicErrorHelper (helperName : String) (code : Nat) : YulStmt :=
YulStmt.funcDef helperName [] [] (solidityPanicPayload code)

def panicError0x11Helper : YulStmt :=
panicErrorHelper panicError0x11HelperName 0x11

Expand Down
2 changes: 2 additions & 0 deletions Compiler/CompilationModelFeatureTest.lean
Original file line number Diff line number Diff line change
Expand Up @@ -5731,6 +5731,8 @@ set_option maxRecDepth 4096 in
(contains arithmeticPanicYul s!"function {panicError0x11HelperName}()" &&
contains arithmeticPanicYul s!"function {panicError0x12HelperName}()" &&
contains arithmeticPanicYul "shl(224, 0x4e487b71)" &&
contains arithmeticPanicYul "mstore(4, 17)" &&
contains arithmeticPanicYul "mstore(4, 18)" &&
contains arithmeticPanicYul "revert(0, 36)")
let envYul ← expectCompileToYul "env runtime smoke spec" envRuntimeSmokeSpec
expectTrue "address(this) lowers to the Yul address builtin"
Expand Down