Skip to content

Commit e0f8e48

Browse files
committed
Fix CREATE2 ECM low-level deny gate
1 parent fc0dcca commit e0f8e48

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

Compiler/CompilationModel/TrustSurface.lean

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,25 @@ private def collectLowLevelMechanicsFromStmts (stmts : List Stmt) : List String
175175
[]
176176
stmts
177177

178+
private def lowLevelMechanicsFromEcmModule (mod : ECM.ExternalCallModule) : List String :=
179+
match mod.name with
180+
| "create2Deploy" => ["create2"]
181+
| "sstore2ReadCode" => ["extcodecopy"]
182+
| _ => []
183+
184+
private def collectLowLevelMechanicsFromEcmModules (modules : List ECM.ExternalCallModule) : List String :=
185+
dedupPreserve (modules.flatMap lowLevelMechanicsFromEcmModule)
186+
187+
private def collectUsedEcmModulesFromStmts (stmts : List Stmt) : List ECM.ExternalCallModule :=
188+
dedupEcmModules <|
189+
Stmt.foldList
190+
(fun acc stmt _ =>
191+
match stmt with
192+
| .ecm mod _ => acc ++ [mod]
193+
| _ => acc)
194+
[]
195+
stmts
196+
178197
private def collectAxiomatizedPrimitivesFromStmts (stmts : List Stmt) : List String :=
179198
dedupPreserve <|
180199
Stmt.foldList
@@ -385,7 +404,8 @@ def collectEventEmissionMechanics (spec : CompilationModel) : List String :=
385404

386405
private def isDeniedLowLevelMechanic (mechanic : String) : Bool :=
387406
match mechanic with
388-
| "call" | "staticcall" | "delegatecall" | "create2" | "returndataSize" | "returndataCopy"
407+
| "call" | "staticcall" | "delegatecall" | "create2" | "codecopy" | "extcodecopy"
408+
| "returndataSize" | "returndataCopy"
389409
| "revertReturndata" | "rawRevert" | "returndataOptionalBoolAt" | "blobbasefee" => true
390410
| _ => false
391411

@@ -399,7 +419,8 @@ def collectLowLevelMechanics (spec : CompilationModel) : List String :=
399419
| some ctor => ctor.body
400420
| none => []
401421
let allStmts := stmtsFromCtor ++ spec.functions.flatMap stmtsFromFn
402-
collectLowLevelMechanicsFromStmts allStmts
422+
dedupPreserve (collectLowLevelMechanicsFromStmts allStmts ++
423+
collectLowLevelMechanicsFromEcmModules (collectUsedEcmModulesFromStmts allStmts))
403424

404425
/-- Collect partially modeled linear-memory mechanics used by a spec. -/
405426
def collectLinearMemoryMechanics (spec : CompilationModel) : List String :=
@@ -667,16 +688,6 @@ private def collectUsedExternalNamesByStatus
667688
example : collectUsedExternalNamesFromStmts [stmtExternalArgSmoke] = ["oracle"] := by
668689
native_decide
669690

670-
private def collectUsedEcmModulesFromStmts (stmts : List Stmt) : List ECM.ExternalCallModule :=
671-
dedupEcmModules <|
672-
Stmt.foldList
673-
(fun acc stmt _ =>
674-
match stmt with
675-
| .ecm mod _ => acc ++ [mod]
676-
| _ => acc)
677-
[]
678-
stmts
679-
680691
/-- Collect ECM modules that are actually referenced by the spec, including
681692
constructor bodies. This shared view keeps machine-readable reports and
682693
compiler summaries aligned. -/
@@ -923,13 +934,15 @@ private def usageSiteSummary
923934
(localObligations : List LocalObligation)
924935
(stmts : List Stmt) :
925936
UsageSiteSummary :=
926-
let mechanics := collectLowLevelMechanicsFromStmts stmts
937+
let siteModules := collectUsedEcmModulesFromStmts stmts
938+
let mechanics :=
939+
dedupPreserve (collectLowLevelMechanicsFromStmts stmts ++
940+
collectLowLevelMechanicsFromEcmModules siteModules)
927941
let eventEmission := collectEventEmissionMechanicsFromStmts stmts
928942
let proxyUpgradeability := collectProxyUpgradeabilityMechanicsFromMechanics mechanics
929943
let runtimeIntrospection := collectRuntimeIntrospectionMechanicsFromStmts stmts
930944
let primitives := collectAxiomatizedPrimitivesFromStmts stmts
931945
let siteExternals := collectUsedExternalAssumptionsFromStmts spec.externals stmts
932-
let siteModules := collectUsedEcmModulesFromStmts stmts
933946
let siteLocalObligations := collectLocalObligationsFromStmts localObligations stmts
934947
let siteUnsafeYulContracts := collectUnsafeYulContractsFromStmts stmts
935948
let siteUnsafeBlocks := collectUnsafeBlockReasonsFromStmts stmts

Compiler/CompilationModelFeatureTest.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6185,6 +6185,13 @@ set_option maxRecDepth 4096 in
61856185
contains macroCreate2SSTORE2TrustReport "\"module\":\"sstore2ReadCode\"" &&
61866186
contains macroCreate2SSTORE2TrustReport "\"assumption\":\"create2_initcode_layout\"" &&
61876187
contains macroCreate2SSTORE2TrustReport "\"assumption\":\"sstore2_pointer_code_layout\"")
6188+
expectTrue "macro create2/SSTORE2 trust report surfaces low-level mechanics"
6189+
(contains macroCreate2SSTORE2TrustReport "\"modeledLowLevelMechanics\":[\"create2\",\"extcodecopy\"]")
6190+
let macroCreate2SSTORE2LowLevelLines :=
6191+
String.intercalate "\n" (emitLowLevelMechanicsUsageSiteLines [Contracts.Smoke.Create2SSTORE2Smoke.spec])
6192+
expectTrue "macro create2/SSTORE2 deny-low-level diagnostics include ECM mechanics"
6193+
(contains macroCreate2SSTORE2LowLevelLines "- Create2SSTORE2Smoke [function:deploy]: create2" &&
6194+
contains macroCreate2SSTORE2LowLevelLines "- Create2SSTORE2Smoke [function:readCode]: extcodecopy")
61886195
let macroCallbackYul ←
61896196
expectCompileToYul "macro callback ABI smoke spec" Contracts.Smoke.CallbackABISmoke.spec
61906197
expectTrue "macro callback ABI surface stores selector and bytes length"

0 commit comments

Comments
 (0)