Repository navigation
Expand file tree
/
Copy pathModelCorrect.lean
More file actions
48 lines (40 loc) · 2.33 KB
/
Copy pathModelCorrect.lean
File metadata and controls
48 lines (40 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import FeProofs.ERC20.ExportedCorrect
import FeProofs.ERC20.SonatinaCorrect
/-!
# FeERC20: the bytecode refines the hand-written model
The certificates of the exported contract (`SonatinaCorrect.lean`) carry over to the hand-written
model: each exported entry ends as the model's does (`runtime_endsAs`, `init_endsAs`), so the
bytecode's result, which agrees with the exported run, agrees with the model's (`agrees_endsAs`).
The runtime certificate is on calldata below `2 ^ 64` bytes (`CalldataFits`), as the exported
one is, where a certificate of the bytecode alone (`Refines`) is on calldata below `2 ^ 256`.
-/
open Ethereum Ethereum.EVM Fe Fe.EVM
namespace FeProofs.ERC20
/-- A result that agrees with a run agrees with any run that it ends as: `Agrees.of_endsAs` the
other way. -/
theorem agrees_endsAs {p : Profile} {evm : EvmResult}
{a b : Option (Except (Exit World) (ByteArray × World))} (h : EndsAs a b)
(ha : Agrees p evm a) : Agrees p evm b := by
cases h with
| stop_ok hacc hl _ | stop_stop hacc hl _ | ok_ok hacc hl _ | ok_stop hacc hl _ =>
simpa only [Agrees, hacc, hl] using ha
| exit f => exact ha
| panic_revert code => exact ha
| diverge => exact ha
/-- The runtime bytecode refines the hand-written model, on calldata below `2 ^ 64` bytes. -/
theorem feERC20RefinesModel : RefinesOn .P0 feERC20Bytecode Model.contract CalldataFits :=
fun σ σ₀ g A I tail hcode htail hown hfits =>
(Sonatina.feERC20RefinesExportedP1.toP0 σ σ₀ g A I tail hcode htail hown hfits).imp id
fun ⟨feed, h⟩ => ⟨feed, agrees_endsAs (Exported.runtime_endsAs I (World.init σ A feed)
(by simp [World.init, UInt256.size]) hfits) h⟩
/-- Deployment with one ABI-encoded `uint256` argument, the initial supply, refines the
hand-written constructor. -/
theorem feERC20DeployRefinesModel :
RefinesDeploy .P0 feERC20CreationBytecode feERC20Bytecode Model.contract
(fun args => ∃ v : UInt256, args = ctorTail v) := by
rintro σ σ₀ g A I args ⟨v, rfl⟩ hcode hown hperm
refine (Sonatina.feERC20DeployRefinesExportedP1.toP0 σ σ₀ g A I _ ⟨v, rfl⟩ hcode hown
hperm).imp id fun ⟨feed, h⟩ => ⟨feed, ?_⟩
simpa [Model.contract, ByteArray.append_empty] using agrees_endsAs (Exported.init_endsAs v _ I
(World.init σ A feed) (by simp [World.init, UInt256.size])) h
end FeProofs.ERC20