Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
fc6b2b9
proofs: expose native EVMYulLean transition target
claude Apr 22, 2026
cdadf59
docs: clarify verity helper calls
claude Apr 22, 2026
1640081
proofs: track native transition blockers
claude Apr 22, 2026
ebbd280
proofs: harden native runtime smoke coverage
claude Apr 22, 2026
747ba1b
proofs: document native env defaults
claude Apr 22, 2026
3ecef1d
proofs: pin native dispatch selector cases
claude Apr 22, 2026
d163384
proofs: pin native dispatch case bodies
claude Apr 22, 2026
0be3e6c
proofs: pin native calldata bridge bytes
claude Apr 22, 2026
14040ca
proofs: pin native dispatcher selector expression
claude Apr 22, 2026
4d91760
docs: clarify native dispatcher execution blocker
claude Apr 22, 2026
0b516fc
proofs: pin native error rollback projection
claude Apr 22, 2026
4d28241
proofs: require native observable slots
claude Apr 22, 2026
e059708
proofs: pin native observable sload
claude Apr 22, 2026
8a5a25d
proofs: cover native IR entrypoint
claude Apr 22, 2026
01fad08
proofs: cover native log projection arities
claude Apr 22, 2026
3a9451c
proofs: cover native transient storage
claude Apr 22, 2026
ef27bda
proofs: cover native stop halt projection
claude Apr 22, 2026
b0d0a87
proofs: cover native value result projection
claude Apr 22, 2026
17c20a2
proofs: cover native return halt projection
claude Apr 22, 2026
616e39d
proofs: pin native halt builtin lowering
claude Apr 22, 2026
93f1b09
proofs: cover native ok storage projection
claude Apr 22, 2026
6e4bb81
proofs: pin native final mapping projection
claude Apr 22, 2026
6846a98
proofs: pin native helper call partition
claude Apr 22, 2026
d846ae2
proofs: pin native initial state bridge
claude Apr 22, 2026
8949e7b
proofs: pin native nested helper rejection
claude Apr 22, 2026
8b431c8
proofs: pin native hard error rollback
claude Apr 22, 2026
14103b9
proofs: pin native return dispatch lowering
claude Apr 22, 2026
4d5013f
proofs: pin native explicit storage slots
claude Apr 22, 2026
41ad1ff
proofs: pin native revert rollback
claude Apr 22, 2026
38cc57b
proofs: pin native IR slot forwarding
claude Apr 22, 2026
c6cf8f0
proofs: pin native transaction environment
claude Apr 22, 2026
3a36713
proofs: name native bridge invariants
claude Apr 22, 2026
0633d53
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
1b303a7
proofs: name native projection outcomes
claude Apr 22, 2026
ed9ce9f
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
a91031c
proofs: name native initial state invariants
claude Apr 22, 2026
f00b839
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
01738dd
proofs: name native storage seeding invariant
claude Apr 22, 2026
4569161
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
ebae796
proofs: name native execution pipeline invariant
claude Apr 22, 2026
8d70342
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
ac1e113
proofs: name native IR execution pipeline invariant
claude Apr 22, 2026
8b5128e
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
3247230
proofs: name native account installation invariant
claude Apr 22, 2026
527fd06
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
d36804d
proofs: name native environment defaults invariant
claude Apr 22, 2026
4d44138
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
661f8e7
proofs: name native calldata size invariant
claude Apr 22, 2026
7e34efb
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
f779f37
proofs: name native halt projection invariants
claude Apr 22, 2026
ae5bb73
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
116f924
proofs: name native event projection invariants
claude Apr 22, 2026
79677ed
chore: auto-refresh derived artifacts
github-actions[bot] Apr 22, 2026
6b268a7
proofs: name omitted native storage invariant
claude Apr 22, 2026
f5d763e
proofs: name native finalMappings invariant
claude Apr 22, 2026
120e053
proofs: name native final storage invariants
claude Apr 22, 2026
b5e39b9
proofs: name native result observable invariants
claude Apr 22, 2026
08601d4
proofs: name missing native account storage invariant
claude Apr 22, 2026
cba4038
proofs: name native missing slot result invariants
claude Apr 22, 2026
193e6d6
proofs: name native final mapping invariants
claude Apr 22, 2026
e76a912
proofs: name native non-word return fallback
claude Apr 22, 2026
7f41306
proofs: name native call lowering invariants
claude Apr 22, 2026
e132814
proofs: name native environment bridge fields
claude Apr 22, 2026
71fe730
scripts: recognize partial defs in proof length check
claude Apr 22, 2026
985d7d5
scripts: test partial defs terminate proof spans
claude Apr 22, 2026
f10f5fd
ci: include native harness in evmyullean probe
claude Apr 22, 2026
92092ed
proofs: compare native env smoke with oracle
claude Apr 22, 2026
cb41fda
ci: guard native transition doc status
claude Apr 22, 2026
2799bb3
ci: guard native observable slot caveat
claude Apr 22, 2026
373790b
ci: guard native observable slot api
claude Apr 22, 2026
20e7b90
contracts: close evmyullean transition blockers
claude Apr 22, 2026
f85598c
contracts: harden overload and env accessors
claude Apr 22, 2026
30d108d
contracts: add migration parity surfaces
claude Apr 22, 2026
e01b323
contracts: remove legacy internal call surface
claude Apr 22, 2026
ef46e5b
contracts: fix overload review regressions
claude Apr 22, 2026
647f2f3
contracts: memoize tuple array element index
claude Apr 22, 2026
a9ec28c
contracts: fail closed on ambiguous overload lookup
claude Apr 22, 2026
c06ab65
compiler: recurse trust surface through array element words
claude Apr 22, 2026
ea21ba6
compiler: reject internal external name collisions
claude Apr 22, 2026
909125f
proofs: cover native selector bytes and new source cases
claude Apr 22, 2026
0724aad
contracts: close tuple array element review gaps
claude Apr 22, 2026
04e2186
proofs: add native dispatch oracle
claude Apr 22, 2026
2094769
contracts: harden overload generated names
claude Apr 22, 2026
57ccf1f
proofs: cover memory return native oracle
claude Apr 22, 2026
aae4b46
compiler: document selector-keyed overload dispatch
claude Apr 22, 2026
1b32fd5
proofs: cover native calldata argument oracle
claude Apr 22, 2026
cd0ea42
evmyullean: lower native dispatch lazily
claude Apr 22, 2026
82b7a89
proofs: cover native mapping oracle shapes
claude Apr 22, 2026
d3305cb
evmyullean: scope lazy native dispatch
claude Apr 22, 2026
8ff72e6
proofs: cover native packed mapping oracle
claude Apr 22, 2026
a823227
evmyullean: thread native switch ids
claude Apr 22, 2026
2f1f16a
macro: accept qualified blobbasefee
claude Apr 22, 2026
dba993a
evmyullean: guard native switch fallthrough
claude Apr 22, 2026
bdaa1a9
ci: guard native theorem transition target
claude Apr 22, 2026
6ffd034
ci: pin unbridged native env boundary
claude Apr 22, 2026
d595759
evmyullean: remove dead native stmt wrapper
claude Apr 22, 2026
e484cb8
compilation: split array element helper gates
claude Apr 22, 2026
2e40dd4
macro: reject ABI-erased newtype overloads
claude Apr 22, 2026
f6d9c68
proofs: expose native runtime preservation seam
claude Apr 22, 2026
06eed0e
evmyullean: validate native environment reads
claude Apr 22, 2026
1155569
evmyullean: freshen native switch temps
claude Apr 22, 2026
f1b975a
evmyullean: reserve function switch temps
claude Apr 22, 2026
1b366a0
proofs: align native bridge observables
claude Apr 22, 2026
7d96db1
evmyullean: validate native env on selected path
claude Apr 22, 2026
b1a4551
compiler: restrict plain arrayElement to word arrays
claude Apr 22, 2026
f037645
compiler: share array element usage traversal
claude Apr 22, 2026
9511f9d
proofs: add native bridge intro theorem
claude Apr 22, 2026
f6cee4b
proofs: expose lowered native dispatcher bridge
claude Apr 23, 2026
96e5f23
compiler: preserve shadowed context accessors
claude Apr 23, 2026
2c5e3bc
compiler: include package roots for module imports
claude Apr 23, 2026
08db836
compiler: simplify array element usage detection
claude Apr 23, 2026
9b34373
tests: cover context accessor shadow smoke
claude Apr 23, 2026
ceb10ec
proofs: expose native runtime lowering equations
claude Apr 23, 2026
ac78d5a
evmyullean: normalize native dispatch selector
claude Apr 23, 2026
5e3e487
macro: track tuple array return temp
claude Apr 23, 2026
36a92a9
evmyullean: expose statement native lowering equations
claude Apr 23, 2026
fbf26e9
macro: resolve declared context-name shadows
claude Apr 23, 2026
febf07f
proofs: expose native dispatcher block bridge
claude Apr 23, 2026
edd96ef
proofs: target lowered dispatcher block
claude Apr 23, 2026
728b822
proofs: expose raw native dispatcher exec
claude Apr 23, 2026
80d6396
proofs: narrow native dispatcher agreement
claude Apr 23, 2026
98b8ed7
compiler: allow namespaced internal helper names
claude Apr 23, 2026
9c340b9
proofs: expose native selector evaluation
claude Apr 23, 2026
8cbd225
compiler: lower storage words in typed ir
claude Apr 23, 2026
33aa242
proofs: expose native selector recomposition
claude Apr 23, 2026
31d0c27
proofs: reduce native selector byte decoding
claude Apr 23, 2026
f101a02
semantics: execute setStorageWord in source model
claude Apr 23, 2026
e7ea5ea
proofs: reduce native selector read bridge
claude Apr 23, 2026
7ece6e6
proofs: prove native selector evaluation
claude Apr 23, 2026
f93cb23
runtime: mirror packed address word writes
claude Apr 23, 2026
b5f384e
proofs: expose native switch guard execution
claude Apr 23, 2026
0b853a8
semantics: mirror raw storage word writes
claude Apr 23, 2026
ade837d
compiler: scan nested array helper usage
claude Apr 23, 2026
f478d28
proofs: expose native switch selected case
claude Apr 23, 2026
6763a5b
compiler: scope duplicate signatures to dispatch
claude Apr 23, 2026
7ca5e75
proofs: skip matched native switch cases
claude Apr 23, 2026
d1562ac
runtime: ignore user functions in native builtin scan
claude Apr 23, 2026
97d7abe
compiler: clarify array element word offsets
claude Apr 23, 2026
e67f6b0
proofs: package marked native switch case
claude Apr 23, 2026
0d6e127
ci: register packed address macro smoke
claude Apr 23, 2026
12e4432
ci: sync evmyullean fork audit pin
claude Apr 23, 2026
fdba4d3
proofs: package native switch prefix
claude Apr 23, 2026
79024ee
compiler: wrap storage word slots
claude Apr 23, 2026
be21bb8
proofs: package native switch freshness
claude Apr 23, 2026
9580577
proofs: package native switch default guard
claude Apr 23, 2026
bc262bb
proofs: package native switch case miss
claude Apr 23, 2026
194ef58
proofs: generalize native switch guard fuel
claude Apr 23, 2026
6355ddc
proofs: prove native switch case chains
claude Apr 23, 2026
9856714
proofs: package native switch defaults
claude Apr 23, 2026
19edb78
macro: erase ADTs in ABI overload keys
claude Apr 23, 2026
07b3ac0
proofs: bridge native switch selector lookup
claude Apr 23, 2026
c61a0a8
checks: address native transition review findings
claude Apr 23, 2026
11b2cae
proofs: factor native switch body preservation
claude Apr 23, 2026
ef96d23
typed-ir: reject ambiguous signature lookup
claude Apr 23, 2026
e947d8b
proofs: compose native switch defaults
claude Apr 23, 2026
234807f
proofs: preserve native switch case lookup
claude Apr 23, 2026
a30d023
proofs: parameterize native switch prefix
claude Apr 23, 2026
0e8efb2
proofs: expose native switch block parts
claude Apr 23, 2026
4698356
proofs: bridge raw native switch blocks
claude Apr 23, 2026
f363b2b
proofs: trim native switch proof guard
claude Apr 23, 2026
b1e3aa0
native: reject unbridged header builtins
claude Apr 23, 2026
070a5f8
proofs: package native assignment preservation
claude Apr 23, 2026
54c5e8d
proofs: stage native dispatcher bridge work
claude Apr 24, 2026
9256d4d
chore: auto-refresh derived artifacts
github-actions[bot] Apr 24, 2026
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
15 changes: 11 additions & 4 deletions .github/workflows/evmyullean-fork-conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ name: EVMYulLean fork conformance
# Weekly probe that the pinned lfglabs-dev/EVMYulLean fork still
# satisfies Verity's bridge assumptions: the fork audit and adapter
# report artifacts are in sync, adapter correctness still builds,
# all universal bridge lemmas still build, the public EndToEnd
# EVMYulLean target still builds, and all 123 concrete `native_decide`
# bridge-equivalence tests still pass.
# all universal bridge lemmas still build, the native transition harness still
# builds, emitted dispatcher native/reference oracle coverage still passes, the
# public EndToEnd EVMYulLean target still builds, and all 123 concrete
# `native_decide` bridge-equivalence tests still pass.
#
# Burn-in: the probe step is captured with `continue-on-error: true`
# during the two-week window starting 2026-04-20 (see issue #1722 plan
Expand Down Expand Up @@ -36,6 +37,9 @@ on:
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanBodyClosure.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanBridgeLemmas.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanBridgeTest.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanNativeHarness.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanNativeDispatchOracleTest.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanNativeSmokeTest.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanRetarget.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanSignedArithSpec.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanSourceExprClosure.lean'
Expand All @@ -58,6 +62,9 @@ on:
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanBodyClosure.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanBridgeLemmas.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanBridgeTest.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanNativeHarness.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanNativeDispatchOracleTest.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanNativeSmokeTest.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanRetarget.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanSignedArithSpec.lean'
- 'Compiler/Proofs/YulGeneration/Backends/EvmYulLeanSourceExprClosure.lean'
Expand Down Expand Up @@ -160,7 +167,7 @@ jobs:
"make test-evmyullean-fork",
"```",
"",
"This guard checks the pinned EVMYulLean fork audit, checks the adapter report, rebuilds adapter correctness and the public EndToEnd target, and runs the concrete bridge-equivalence tests."
"This guard checks the pinned EVMYulLean fork audit, checks the adapter report, rebuilds adapter correctness, the native transition harness, and the public EndToEnd target, and runs the concrete bridge-equivalence tests."
];
const body = bodyLines.join("\n");

Expand Down
5 changes: 3 additions & 2 deletions AXIOMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ the EVM.
**Soundness controls**:
- `make check` validates the fork-audit artifact against `lake-manifest.json`.
- `make test-evmyullean-fork` rechecks the fork audit, checks the adapter
report, rebuilds adapter correctness and the public EndToEnd EVMYulLean
target, and runs the concrete `native_decide` bridge-equivalence tests.
report, rebuilds adapter correctness, the native transition harness, the
public EndToEnd EVMYulLean target, and the concrete `native_decide`
bridge-equivalence tests.
- `.github/workflows/evmyullean-fork-conformance.yml` runs the conformance probe
weekly; after the burn-in ending 2026-05-04, scheduled/manual failures fail
the workflow and open or update a GitHub issue for drift triage.
Expand Down
4 changes: 4 additions & 0 deletions Compiler/CompilationModel/AbiHelpers.lean
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def eventSignature (eventDef : EventDef) : String :=
def errorSignature (errorDef : ErrorDef) : String :=
s!"{errorDef.name}(" ++ String.intercalate "," (errorDef.params.map paramTypeToSolidityString) ++ ")"

def functionSignature (fn : FunctionSpec) : String :=
let params := fn.params.map (fun p => paramTypeToSolidityString p.ty)
s!"{fn.name}(" ++ String.intercalate "," params ++ ")"
Comment thread
Th0rgal marked this conversation as resolved.

def storageArrayElemTypeToParamType : StorageArrayElemType → ParamType
| .uint256 => .uint256
| .address => .address
Expand Down
10 changes: 10 additions & 0 deletions Compiler/CompilationModel/Compile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,16 @@ def compileStmt (fields : List Field) (events : List EventDef := [])
compileSetStorage fields dynamicSource field value
| Stmt.setStorageAddr field value =>
compileSetStorage fields dynamicSource field value true
| Stmt.setStorageWord field wordOffset value =>
match findFieldWithResolvedSlot fields field with
| some (_f, slot) => do
let valueExpr ← compileExpr fields dynamicSource value
let slotExpr :=
if wordOffset == 0 then YulExpr.lit slot
else YulExpr.call "add" [YulExpr.lit slot, YulExpr.lit wordOffset]
pure [YulStmt.expr (YulExpr.call "sstore" [slotExpr, valueExpr])]
| none =>
throw s!"Compilation error: unknown storage field '{field}' in setStorageWord"
| Stmt.storageArrayPush field value =>
compileStorageArrayPush fields dynamicSource field value
| Stmt.storageArrayPop field =>
Expand Down
32 changes: 24 additions & 8 deletions Compiler/CompilationModel/Dispatch.lean
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,14 @@ private def validateCompileInputsBeforeFieldWriteConflict
for ext in spec.externals do
let _ ← externalFunctionReturns ext
validateInteropExternalSpec ext
match firstDuplicateName (spec.functions.map (·.name)) with
match firstDuplicateName ((spec.functions.filter (fun fn => !fn.isInternal)).map functionSignature) with
| some dup =>
throw s!"Compilation error: duplicate function name '{dup}' in {spec.name}"
throw s!"Compilation error: duplicate function signature '{dup}' in {spec.name}"
Comment thread
Th0rgal marked this conversation as resolved.
Comment thread
cursor[bot] marked this conversation as resolved.
| none =>
pure ()
match firstDuplicateName ((spec.functions.filter (·.isInternal)).map (·.name)) with
| some dup =>
throw s!"Compilation error: duplicate internal function name '{dup}' in {spec.name}; internal function Yul definitions are keyed by name"
Comment thread
cursor[bot] marked this conversation as resolved.
| none =>
Comment thread
Th0rgal marked this conversation as resolved.
pure ()
match firstDuplicateName (spec.errors.map (·.name)) with
Expand Down Expand Up @@ -352,11 +357,13 @@ def validateCompileInputs (spec : CompilationModel) (selectors : List Nat) : Exc
| none =>
pure ()
let mappingHelpersRequired := usesMapping fields
let arrayHelpersRequired := contractUsesArrayElement spec
let arrayHelpersRequired := contractUsesPlainArrayElement spec
let arrayElementWordHelpersRequired := contractUsesArrayElementWord spec
let storageArrayHelpersRequired := contractUsesStorageArrayElement spec
let dynamicBytesEqHelpersRequired := contractUsesDynamicBytesEq spec
match firstReservedExternalCollision
spec mappingHelpersRequired arrayHelpersRequired storageArrayHelpersRequired dynamicBytesEqHelpersRequired with
spec mappingHelpersRequired arrayHelpersRequired arrayElementWordHelpersRequired
storageArrayHelpersRequired dynamicBytesEqHelpersRequired with
| some name =>
if name.startsWith internalFunctionPrefix then
throw s!"Compilation error: external declaration '{name}' uses reserved prefix '{internalFunctionPrefix}' ({issue756Ref})."
Expand All @@ -380,7 +387,8 @@ def compileValidatedCore (spec : CompilationModel) (selectors : List Nat) : Exce
let externalFns := spec.functions.filter (fun fn => !fn.isInternal && !isInteropEntrypointName fn.name)
let internalFns := spec.functions.filter (·.isInternal)
let mappingHelpersRequired := usesMapping fields
let arrayHelpersRequired := contractUsesArrayElement spec
let arrayHelpersRequired := contractUsesPlainArrayElement spec
let arrayElementWordHelpersRequired := contractUsesArrayElementWord spec
let storageArrayHelpersRequired := contractUsesStorageArrayElement spec
let dynamicBytesEqHelpersRequired := contractUsesDynamicBytesEq spec
let fallbackSpec ← pickUniqueFunctionByName "fallback" spec.functions
Expand All @@ -389,10 +397,18 @@ def compileValidatedCore (spec : CompilationModel) (selectors : List Nat) : Exce
compileFunctionSpec fields spec.events spec.errors spec.adtTypes sel fnSpec
let internalFuncDefs ← internalFns.mapM (compileInternalFunction fields spec.events spec.errors spec.adtTypes)
let arrayElementHelpers :=
if arrayHelpersRequired then
[checkedArrayElementCalldataHelper, checkedArrayElementMemoryHelper]
(if arrayHelpersRequired then
[ checkedArrayElementCalldataHelper
, checkedArrayElementMemoryHelper
]
else
[]
[]) ++
(if arrayElementWordHelpersRequired then
[ checkedArrayElementWordCalldataHelper
, checkedArrayElementWordMemoryHelper
]
Comment thread
cursor[bot] marked this conversation as resolved.
else
[])
let storageArrayElementHelpers :=
if storageArrayHelpersRequired then
[checkedStorageArrayElementHelper]
Expand Down
33 changes: 33 additions & 0 deletions Compiler/CompilationModel/DynamicData.lean
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ def checkedArrayElementCalldataHelperName : String :=
def checkedArrayElementMemoryHelperName : String :=
"__verity_array_element_memory_checked"

def checkedArrayElementWordCalldataHelperName : String :=
"__verity_array_element_word_calldata_checked"

def checkedArrayElementWordMemoryHelperName : String :=
"__verity_array_element_word_memory_checked"

def checkedStorageArrayElementHelperName : String :=
"__verity_storage_array_element_checked"

Expand Down Expand Up @@ -50,6 +56,33 @@ def checkedArrayElementCalldataHelper : YulStmt :=
def checkedArrayElementMemoryHelper : YulStmt :=
checkedArrayElementHelper checkedArrayElementMemoryHelperName "mload"

private def checkedArrayElementWordHelper (helperName loadOp : String) : YulStmt :=
let elementWordIndex :=
YulExpr.call "add" [
YulExpr.call "mul" [YulExpr.ident "index", YulExpr.ident "element_words"],
YulExpr.ident "word_offset"
]
let byteOffset := YulExpr.call "mul" [elementWordIndex, YulExpr.lit 32]
YulStmt.funcDef helperName ["data_offset", "length", "index", "element_words", "word_offset"] ["word"] [
YulStmt.if_ (YulExpr.call "iszero" [
YulExpr.call "lt" [YulExpr.ident "index", YulExpr.ident "length"]
]) [
YulStmt.expr (YulExpr.call "revert" [YulExpr.lit 0, YulExpr.lit 0])
],
YulStmt.assign "word" (YulExpr.call loadOp [
YulExpr.call "add" [
YulExpr.ident "data_offset",
byteOffset
]
])
]

def checkedArrayElementWordCalldataHelper : YulStmt :=
checkedArrayElementWordHelper checkedArrayElementWordCalldataHelperName "calldataload"

def checkedArrayElementWordMemoryHelper : YulStmt :=
checkedArrayElementWordHelper checkedArrayElementWordMemoryHelperName "mload"

def checkedStorageArrayElementHelper : YulStmt :=
YulStmt.funcDef checkedStorageArrayElementHelperName ["slot", "index"] ["word"] [
YulStmt.let_ "__array_len" (YulExpr.call "sload" [YulExpr.ident "slot"]),
Expand Down
17 changes: 17 additions & 0 deletions Compiler/CompilationModel/ExpressionCompile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,23 @@ def compileExpr (fields : List Field)
YulExpr.ident s!"{name}_length",
indexExpr
])
| Expr.arrayElementWord name index elementWords wordOffset => do
if elementWords == 0 then
throw s!"Compilation error: Expr.arrayElementWord '{name}' requires elementWords > 0"
else if wordOffset >= elementWords then
throw s!"Compilation error: Expr.arrayElementWord '{name}' wordOffset {wordOffset} is outside element width {elementWords}"
else
let indexExpr ← compileExpr fields dynamicSource index
let helperName := match dynamicSource with
| .calldata => checkedArrayElementWordCalldataHelperName
| .memory => checkedArrayElementWordMemoryHelperName
pure (YulExpr.call helperName [
YulExpr.ident s!"{name}_data_offset",
YulExpr.ident s!"{name}_length",
indexExpr,
YulExpr.lit elementWords,
YulExpr.lit wordOffset
])
| Expr.storageArrayLength field =>
match findFieldWithResolvedSlot fields field with
| some (f, slot) =>
Expand Down
9 changes: 6 additions & 3 deletions Compiler/CompilationModel/LogicalPurity.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ partial def exprContainsCallLike (expr : Expr) : Bool :=
| Expr.structMember2 _ key1 key2 _ =>
exprContainsCallLike key1 || exprContainsCallLike key2
| Expr.storageArrayElement _ index
| Expr.arrayElement _ index =>
| Expr.arrayElement _ index
| Expr.arrayElementWord _ index _ _ =>
exprContainsCallLike index
| Expr.dynamicBytesEq _ _ =>
false
Expand Down Expand Up @@ -110,7 +111,8 @@ def exprContainsUnsafeLogicalCallLike (expr : Expr) : Bool :=
| Expr.mapping2 _ key1 key2 | Expr.mapping2Word _ key1 key2 _
| Expr.structMember2 _ key1 key2 _ =>
exprContainsUnsafeLogicalCallLike key1 || exprContainsUnsafeLogicalCallLike key2
| Expr.storageArrayElement _ index | Expr.arrayElement _ index | Expr.returndataOptionalBoolAt index =>
| Expr.storageArrayElement _ index | Expr.arrayElement _ index
| Expr.arrayElementWord _ index _ _ | Expr.returndataOptionalBoolAt index =>
exprContainsUnsafeLogicalCallLike index
| Expr.dynamicBytesEq _ _ =>
false
Expand Down Expand Up @@ -152,7 +154,8 @@ termination_by es => sizeOf es
decreasing_by all_goals simp_wf; all_goals omega

def stmtContainsUnsafeLogicalCallLike : Stmt → Bool
| Stmt.letVar _ value | Stmt.assignVar _ value | Stmt.setStorage _ value | Stmt.setStorageAddr _ value |
| Stmt.letVar _ value | Stmt.assignVar _ value | Stmt.setStorage _ value | Stmt.setStorageAddr _ value
| Stmt.setStorageWord _ _ value |
Stmt.storageArrayPush _ value |
Stmt.return value | Stmt.require value _ =>
exprContainsUnsafeLogicalCallLike value
Expand Down
11 changes: 9 additions & 2 deletions Compiler/CompilationModel/ParamLoading.lean
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ def isScalarParamType : ParamType → Bool
| ParamType.uint256 | ParamType.int256 | ParamType.uint8 | ParamType.address | ParamType.bool | ParamType.bytes32 => true
| _ => false

private def dynamicArrayElementStrideWords (elemTy : ParamType) : Nat :=
if isDynamicParamType elemTy then
1
else
max 1 (paramHeadSize elemTy / 32)

private def genDynamicParamLoads
(loadWord : YulExpr → YulExpr) (sizeExpr : YulExpr) (headSize : Nat)
(baseOffset : Nat) (name : String) (ty : ParamType) (headOffset : Nat) :
Expand Down Expand Up @@ -56,10 +62,11 @@ private def genDynamicParamLoads
]) [
YulStmt.expr (YulExpr.call "revert" [YulExpr.lit 0, YulExpr.lit 0])
]]
| ParamType.array _ =>
| ParamType.array elemTy =>
let elemWords := dynamicArrayElementStrideWords elemTy
[YulStmt.if_ (YulExpr.call "gt" [
YulExpr.ident s!"{name}_length",
YulExpr.call "div" [YulExpr.ident tailRemainingName, YulExpr.lit 32]
YulExpr.call "div" [YulExpr.ident tailRemainingName, YulExpr.lit (32 * elemWords)]
Comment thread
Th0rgal marked this conversation as resolved.
]) [
YulStmt.expr (YulExpr.call "revert" [YulExpr.lit 0, YulExpr.lit 0])
]]
Expand Down
23 changes: 22 additions & 1 deletion Compiler/CompilationModel/ScopeValidation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ def validateScopedExprIdentifiers
| none =>
throw s!"Compilation error: {context} references unknown parameter '{name}' in Expr.arrayElement"
validateScopedExprIdentifiers context params paramScope dynamicParams localScope constructorArgCount index
| Expr.arrayElementWord name index elementWords wordOffset => do
if elementWords == 0 then
throw s!"Compilation error: {context} Expr.arrayElementWord '{name}' requires elementWords > 0"
else if wordOffset >= elementWords then
throw s!"Compilation error: {context} Expr.arrayElementWord '{name}' wordOffset {wordOffset} is outside element width {elementWords}"
match findParamType params name with
| some ty@(ParamType.array elemTy) =>
if isDynamicParamType elemTy then
throw s!"Compilation error: {context} Expr.arrayElementWord '{name}' requires an array parameter with static ABI-word elements, got {repr ty}"
else
let expectedWords := paramHeadSize elemTy / 32
if elementWords == expectedWords then
pure ()
else
throw s!"Compilation error: {context} Expr.arrayElementWord '{name}' element width {elementWords} does not match ABI width {expectedWords} for {repr ty}"
| some ty =>
throw s!"Compilation error: {context} Expr.arrayElementWord '{name}' requires array parameter, got {repr ty}"
| none =>
throw s!"Compilation error: {context} references unknown parameter '{name}' in Expr.arrayElementWord"
validateScopedExprIdentifiers context params paramScope dynamicParams localScope constructorArgCount index
Comment thread
Th0rgal marked this conversation as resolved.
| Expr.mapping _ key | Expr.mappingWord _ key _ | Expr.mappingPackedWord _ key _ _ | Expr.mappingUint _ key
| Expr.structMember _ key _ =>
validateScopedExprIdentifiers context params paramScope dynamicParams localScope constructorArgCount key
Expand Down Expand Up @@ -263,7 +283,8 @@ def validateScopedStmtIdentifiers
throw s!"Compilation error: {context} assigns to undeclared local variable '{name}'"
validateScopedExprIdentifiers context params paramScope dynamicParams localScope constructorArgCount value
pure localScope
| Stmt.setStorage _ value | Stmt.setStorageAddr _ value | Stmt.return value | Stmt.require value _ => do
| Stmt.setStorage _ value | Stmt.setStorageAddr _ value | Stmt.setStorageWord _ _ value
| Stmt.return value | Stmt.require value _ => do
validateScopedExprIdentifiers context params paramScope dynamicParams localScope constructorArgCount value
pure localScope
| Stmt.storageArrayPush _ value => do
Expand Down
Loading